KeerthiVM commited on
Commit
d0f2ec4
Β·
1 Parent(s): 554f797
Files changed (1) hide show
  1. app.py +21 -20
app.py CHANGED
@@ -31,6 +31,7 @@ torch.cuda.empty_cache()
31
  nest_asyncio.apply()
32
  co = cohere.Client(st.secrets["COHERE_API_KEY"])
33
 
 
34
 
35
  st.set_page_config(page_title="DermBOT", page_icon="🧬", layout="centered")
36
 
@@ -52,7 +53,6 @@ collection_name = "ks_collection_1.5BE"
52
 
53
 
54
 
55
- device = "cuda" if torch.cuda.is_available() else "cpu"
56
 
57
  def get_safe_embedding_model():
58
  model_name = "Alibaba-NLP/gte-Qwen2-1.5B-instruct"
@@ -140,7 +140,8 @@ elif "Gemini" in selected_model:
140
  import google.generativeai as genai
141
  genai.configure(api_key=st.secrets["GEMINI_API_KEY"]) # Store in `.streamlit/secrets.toml`
142
 
143
- gemini_model = genai.GenerativeModel("gemini-2.5-pro-exp-03-25")
 
144
  def get_gemini_response(prompt):
145
  response = gemini_model.generate_content(prompt)
146
  return response.text
@@ -156,7 +157,7 @@ elif "All" in selected_model:
156
  openai_resp = ChatOpenAI(model="gpt-4o", temperature=0.2, api_key=st.secrets["OPENAI_API_KEY"]).invoke(
157
  [{"role": "system", "content": prompt}]).content
158
 
159
- gemini = genai.GenerativeModel("gemini-2.5-pro-exp-03-25")
160
  gemini_resp = gemini.generate_content(prompt).text
161
 
162
  llama = Groq(api_key=st.secrets["GROQ_API_KEY"])
@@ -270,23 +271,23 @@ multilabel_model_path = hf_hub_download(repo_id="santhoshraghu/DermBOT", filenam
270
  multiclass_model_path = hf_hub_download(repo_id="santhoshraghu/DermBOT", filename="best_dermnet_vit_sd.pth")
271
 
272
  def load_model_with_fallback(model_class, weight_path, num_classes, model_name):
273
- try:
274
- print(f"πŸ” Loading {model_name} on GPU...")
275
- model = model_class(num_classes)
276
- model.load_state_dict(torch.load(weight_path, map_location="cuda"))
277
- model.to("cuda")
278
- print(f"βœ… {model_name} loaded on GPU.")
279
- return model
280
- except RuntimeError as e:
281
- if "CUDA out of memory" in str(e):
282
- print(f"⚠️ {model_name} OOM. Falling back to CPU.")
283
- else:
284
- print(f"❌ Error loading {model_name} on CUDA: {e}")
285
- print(f"πŸ”„ Loading {model_name} on CPU...")
286
- model = model_class(num_classes)
287
- model.load_state_dict(torch.load(weight_path, map_location="cpu"))
288
- model.to("cpu")
289
- return model
290
 
291
  # Load both models with fallback
292
  multilabel_model = load_model_with_fallback(SkinViT, multilabel_model_path, len(multilabel_class_names), "SkinViT")
 
31
  nest_asyncio.apply()
32
  co = cohere.Client(st.secrets["COHERE_API_KEY"])
33
 
34
+ device='cuda' if torch.cuda.is_available() else 'cpu'
35
 
36
  st.set_page_config(page_title="DermBOT", page_icon="🧬", layout="centered")
37
 
 
53
 
54
 
55
 
 
56
 
57
  def get_safe_embedding_model():
58
  model_name = "Alibaba-NLP/gte-Qwen2-1.5B-instruct"
 
140
  import google.generativeai as genai
141
  genai.configure(api_key=st.secrets["GEMINI_API_KEY"]) # Store in `.streamlit/secrets.toml`
142
 
143
+ # gemini_model = genai.GenerativeModel("gemini-2.5-pro-exp-03-25")
144
+ gemini_model = genai.GenerativeModel("gemini-2.5-pro-preview-05-06")
145
  def get_gemini_response(prompt):
146
  response = gemini_model.generate_content(prompt)
147
  return response.text
 
157
  openai_resp = ChatOpenAI(model="gpt-4o", temperature=0.2, api_key=st.secrets["OPENAI_API_KEY"]).invoke(
158
  [{"role": "system", "content": prompt}]).content
159
 
160
+ gemini = genai.GenerativeModel("gemini-2.5-pro-preview-05-06")
161
  gemini_resp = gemini.generate_content(prompt).text
162
 
163
  llama = Groq(api_key=st.secrets["GROQ_API_KEY"])
 
271
  multiclass_model_path = hf_hub_download(repo_id="santhoshraghu/DermBOT", filename="best_dermnet_vit_sd.pth")
272
 
273
  def load_model_with_fallback(model_class, weight_path, num_classes, model_name):
274
+ # try:
275
+ print(f"πŸ” Loading {model_name} on GPU...")
276
+ model = model_class(num_classes)
277
+ model.load_state_dict(torch.load(weight_path, map_location=device))
278
+ model.to(device)
279
+ print(f"βœ… {model_name} loaded on GPU.")
280
+ return model
281
+ # except RuntimeError as e:
282
+ # if "CUDA out of memory" in str(e):
283
+ # print(f"⚠️ {model_name} OOM. Falling back to CPU.")
284
+ # else:
285
+ # print(f"❌ Error loading {model_name} on CUDA: {e}")
286
+ # print(f"πŸ”„ Loading {model_name} on CPU...")
287
+ # model = model_class(num_classes)
288
+ # model.load_state_dict(torch.load(weight_path, map_location="cpu"))
289
+ # model.to("cpu")
290
+ # return model
291
 
292
  # Load both models with fallback
293
  multilabel_model = load_model_with_fallback(SkinViT, multilabel_model_path, len(multilabel_class_names), "SkinViT")