Spaces:
Sleeping
Sleeping
jocko
commited on
Commit
Β·
c8b7285
1
Parent(s):
fbf3ec2
fix image similarity detection
Browse files- requirements.txt +3 -2
- src/streamlit_app.py +17 -18
requirements.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
altair
|
| 2 |
pandas
|
| 3 |
-
streamlit
|
| 4 |
torch
|
| 5 |
transformers
|
| 6 |
sentence-transformers
|
|
@@ -8,4 +8,5 @@ datasets
|
|
| 8 |
openai
|
| 9 |
opik
|
| 10 |
comet-llm==2.1.0
|
| 11 |
-
comet_ml==3.33.8
|
|
|
|
|
|
| 1 |
altair
|
| 2 |
pandas
|
| 3 |
+
streamlit~=1.48.0
|
| 4 |
torch
|
| 5 |
transformers
|
| 6 |
sentence-transformers
|
|
|
|
| 8 |
openai
|
| 9 |
opik
|
| 10 |
comet-llm==2.1.0
|
| 11 |
+
comet_ml==3.33.8
|
| 12 |
+
pillow~=11.3.0
|
src/streamlit_app.py
CHANGED
|
@@ -30,12 +30,12 @@ from sentence_transformers import SentenceTransformer, util
|
|
| 30 |
from transformers import CLIPProcessor, CLIPModel
|
| 31 |
from datasets import load_dataset, get_dataset_split_names
|
| 32 |
from PIL import Image
|
| 33 |
-
import
|
| 34 |
import comet_llm
|
| 35 |
from opik import track
|
| 36 |
|
| 37 |
# ========== π API Key ==========
|
| 38 |
-
|
| 39 |
os.environ["OPIK_API_KEY"] = os.getenv("OPIK_API_KEY")
|
| 40 |
os.environ["OPIK_WORKSPACE"] = os.getenv("OPIK_WORKSPACE")
|
| 41 |
# ========== π₯ Load Models ==========
|
|
@@ -86,8 +86,7 @@ def embed_dataset_images(_dataset):
|
|
| 86 |
data = load_medical_data()
|
| 87 |
dataset_image_features = embed_dataset_images(data)
|
| 88 |
|
| 89 |
-
|
| 90 |
-
client = OpenAI(api_key=openai.api_key)
|
| 91 |
# Temporary debug display
|
| 92 |
#st.write("Dataset columns:", data.features.keys())
|
| 93 |
|
|
@@ -117,19 +116,6 @@ def embed_dataset_texts(_texts):
|
|
| 117 |
def embed_query_text(query):
|
| 118 |
return text_model.encode([query], convert_to_tensor=True)[0]
|
| 119 |
|
| 120 |
-
# Pick which text column to use
|
| 121 |
-
TEXT_COLUMN = "complaints" # or "general_complaint", depending on your needs
|
| 122 |
-
|
| 123 |
-
# ========== π§ββοΈ App UI ==========
|
| 124 |
-
st.title("π©Ί Multimodal Medical Chatbot")
|
| 125 |
-
|
| 126 |
-
query = st.text_input("Enter your medical question or symptom description:")
|
| 127 |
-
uploaded_files = st.file_uploader("Upload an image to find similar medical cases:", type=["png", "jpg", "jpeg"], accept_multiple_files=True)
|
| 128 |
-
|
| 129 |
-
st.write(f"Number of files: {len(uploaded_files)}")
|
| 130 |
-
for uploaded_file in uploaded_files:
|
| 131 |
-
st.write(f"File name: {uploaded_file.name}")
|
| 132 |
-
|
| 133 |
@track
|
| 134 |
def get_chat_completion_openai(client, prompt: str):
|
| 135 |
return client.chat.completions.create(
|
|
@@ -150,6 +136,19 @@ def get_similar_prompt(query):
|
|
| 150 |
return data[idx]
|
| 151 |
|
| 152 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
|
| 154 |
if query:
|
| 155 |
with st.spinner("Searching medical cases..."):
|
|
@@ -165,7 +164,7 @@ if query:
|
|
| 165 |
st.markdown(f"**Case Description:** {selected[TEXT_COLUMN]}")
|
| 166 |
|
| 167 |
# GPT Explanation
|
| 168 |
-
if
|
| 169 |
prompt = f"Explain this case in plain English: {selected[TEXT_COLUMN]}"
|
| 170 |
|
| 171 |
explanation = get_chat_completion_openai(client, prompt)
|
|
|
|
| 30 |
from transformers import CLIPProcessor, CLIPModel
|
| 31 |
from datasets import load_dataset, get_dataset_split_names
|
| 32 |
from PIL import Image
|
| 33 |
+
from openai import OpenAI
|
| 34 |
import comet_llm
|
| 35 |
from opik import track
|
| 36 |
|
| 37 |
# ========== π API Key ==========
|
| 38 |
+
OpenAI.api_key = os.getenv("OPENAI_API_KEY")
|
| 39 |
os.environ["OPIK_API_KEY"] = os.getenv("OPIK_API_KEY")
|
| 40 |
os.environ["OPIK_WORKSPACE"] = os.getenv("OPIK_WORKSPACE")
|
| 41 |
# ========== π₯ Load Models ==========
|
|
|
|
| 86 |
data = load_medical_data()
|
| 87 |
dataset_image_features = embed_dataset_images(data)
|
| 88 |
|
| 89 |
+
client = OpenAI(api_key=OpenAI.api_key)
|
|
|
|
| 90 |
# Temporary debug display
|
| 91 |
#st.write("Dataset columns:", data.features.keys())
|
| 92 |
|
|
|
|
| 116 |
def embed_query_text(query):
|
| 117 |
return text_model.encode([query], convert_to_tensor=True)[0]
|
| 118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
@track
|
| 120 |
def get_chat_completion_openai(client, prompt: str):
|
| 121 |
return client.chat.completions.create(
|
|
|
|
| 136 |
return data[idx]
|
| 137 |
|
| 138 |
|
| 139 |
+
# Pick which text column to use
|
| 140 |
+
TEXT_COLUMN = "complaints" # or "general_complaint", depending on your needs
|
| 141 |
+
|
| 142 |
+
# ========== π§ββοΈ App UI ==========
|
| 143 |
+
st.title("π©Ί Multimodal Medical Chatbot")
|
| 144 |
+
|
| 145 |
+
query = st.text_input("Enter your medical question or symptom description:")
|
| 146 |
+
uploaded_files = st.file_uploader("Upload an image to find similar medical cases:", type=["png", "jpg", "jpeg"], accept_multiple_files=True)
|
| 147 |
+
|
| 148 |
+
st.write(f"Number of files: {len(uploaded_files)}")
|
| 149 |
+
for uploaded_file in uploaded_files:
|
| 150 |
+
st.write(f"File name: {uploaded_file.name}")
|
| 151 |
+
|
| 152 |
|
| 153 |
if query:
|
| 154 |
with st.spinner("Searching medical cases..."):
|
|
|
|
| 164 |
st.markdown(f"**Case Description:** {selected[TEXT_COLUMN]}")
|
| 165 |
|
| 166 |
# GPT Explanation
|
| 167 |
+
if OpenAI.api_key:
|
| 168 |
prompt = f"Explain this case in plain English: {selected[TEXT_COLUMN]}"
|
| 169 |
|
| 170 |
explanation = get_chat_completion_openai(client, prompt)
|