vi108 commited on
Commit
87b7ab3
·
verified ·
1 Parent(s): 3b2a51e

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +11 -10
src/streamlit_app.py CHANGED
@@ -28,10 +28,13 @@ from datasets import load_dataset, get_dataset_split_names
28
  from PIL import Image
29
  import openai
30
  import comet_llm
31
- from functools import wraps
32
- from opik import track as opik_track
33
 
 
 
 
34
 
 
35
 
36
 
37
  # ========== 🔑 API Key ==========
@@ -111,13 +114,7 @@ st.title("🩺 Multimodal Medical Chatbot")
111
  query = st.text_input("Enter your medical question or symptom description:")
112
  uploaded_file = st.file_uploader("Upload an image to find similar medical cases:", type=["png", "jpg", "jpeg"])
113
 
114
- def safe_track(func):
115
- @wraps(func)
116
- def wrapper(*args, **kwargs):
117
- return opik_track(func)(*args, **kwargs)
118
- return wrapper
119
-
120
- @safe_track
121
  def get_chat_completion_openai(client, prompt: str):
122
  return client.chat.completions.create(
123
  model="gpt-4o", # or "gpt-4" if you need the older GPT-4
@@ -126,7 +123,7 @@ def get_chat_completion_openai(client, prompt: str):
126
  max_tokens=150
127
  )
128
 
129
- @safe_track
130
  def get_similar_prompt(query):
131
  text_embeddings = embed_dataset_texts(combined_texts) # cached
132
  query_embedding = embed_query_text(query) # recalculated each time
@@ -177,6 +174,8 @@ if query:
177
  st.warning("OpenAI API key not found. Please set OPENAI_API_KEY as a secret environment variable.")
178
 
179
  if uploaded_file is not None:
 
 
180
  query_image = Image.open(uploaded_file).convert("RGB")
181
  st.image(query_image, caption="Your uploaded image", use_container_width=True)
182
 
@@ -199,5 +198,7 @@ if uploaded_file is not None:
199
  similar_img = data[int(idx)]['image']
200
  st.image(similar_img, caption=f"Similarity: {score:.3f}", use_container_width=True)
201
  st.markdown(f"**Case description:** {data[int(idx)]['complaints']}")
 
 
202
 
203
  st.caption("This chatbot is for educational purposes only and does not provide medical advice.")
 
28
  from PIL import Image
29
  import openai
30
  import comet_llm
31
+ from opik import track
 
32
 
33
+ os.environ["STREAMLIT_CONFIG_DIR"] = "/tmp/.streamlit"
34
+ os.environ["STREAMLIT_CACHE_DIR"] = f"{CACHE_BASE}/streamlit_cache"
35
+ os.environ["STREAMLIT_STATIC_DIR"] = f"{CACHE_BASE}/streamlit_static"
36
 
37
+ os.makedirs("/tmp/.streamlit", exist_ok=True)
38
 
39
 
40
  # ========== 🔑 API Key ==========
 
114
  query = st.text_input("Enter your medical question or symptom description:")
115
  uploaded_file = st.file_uploader("Upload an image to find similar medical cases:", type=["png", "jpg", "jpeg"])
116
 
117
+ @track
 
 
 
 
 
 
118
  def get_chat_completion_openai(client, prompt: str):
119
  return client.chat.completions.create(
120
  model="gpt-4o", # or "gpt-4" if you need the older GPT-4
 
123
  max_tokens=150
124
  )
125
 
126
+ @track
127
  def get_similar_prompt(query):
128
  text_embeddings = embed_dataset_texts(combined_texts) # cached
129
  query_embedding = embed_query_text(query) # recalculated each time
 
174
  st.warning("OpenAI API key not found. Please set OPENAI_API_KEY as a secret environment variable.")
175
 
176
  if uploaded_file is not None:
177
+ print('uploading file')
178
+ print(uploaded_file)
179
  query_image = Image.open(uploaded_file).convert("RGB")
180
  st.image(query_image, caption="Your uploaded image", use_container_width=True)
181
 
 
198
  similar_img = data[int(idx)]['image']
199
  st.image(similar_img, caption=f"Similarity: {score:.3f}", use_container_width=True)
200
  st.markdown(f"**Case description:** {data[int(idx)]['complaints']}")
201
+ else:
202
+ print("no image")
203
 
204
  st.caption("This chatbot is for educational purposes only and does not provide medical advice.")