Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +6 -3
src/streamlit_app.py
CHANGED
@@ -78,9 +78,12 @@ text_field = "text" if "text" in data.features else list(data.features.keys())[0
|
|
78 |
|
79 |
# ========== 🧠 Embedding Function ==========
|
80 |
@st.cache_data(show_spinner=False)
|
81 |
-
def
|
82 |
return text_model.encode(_texts, convert_to_tensor=True)
|
83 |
|
|
|
|
|
|
|
84 |
# Pick which text column to use
|
85 |
TEXT_COLUMN = "complaints" # or "general_complaint", depending on your needs
|
86 |
|
@@ -91,8 +94,8 @@ query = st.text_input("Enter your medical question or symptom description:")
|
|
91 |
|
92 |
if query:
|
93 |
with st.spinner("Searching medical cases..."):
|
94 |
-
text_embeddings =
|
95 |
-
query_embedding =
|
96 |
|
97 |
# Compute similarity
|
98 |
cos_scores = util.pytorch_cos_sim(query_embedding, text_embeddings)[0]
|
|
|
78 |
|
79 |
# ========== 🧠 Embedding Function ==========
|
80 |
@st.cache_data(show_spinner=False)
|
81 |
+
def embed_dataset_texts(_texts):
|
82 |
return text_model.encode(_texts, convert_to_tensor=True)
|
83 |
|
84 |
+
def embed_query_text(query):
|
85 |
+
return text_model.encode([query], convert_to_tensor=True)[0]
|
86 |
+
|
87 |
# Pick which text column to use
|
88 |
TEXT_COLUMN = "complaints" # or "general_complaint", depending on your needs
|
89 |
|
|
|
94 |
|
95 |
if query:
|
96 |
with st.spinner("Searching medical cases..."):
|
97 |
+
text_embeddings = embed_dataset_texts(data[TEXT_COLUMN])
|
98 |
+
query_embedding = embed_query_text([query])[0]
|
99 |
|
100 |
# Compute similarity
|
101 |
cos_scores = util.pytorch_cos_sim(query_embedding, text_embeddings)[0]
|