Spaces:
Sleeping
Sleeping
jocko
commited on
Commit
·
1230889
1
Parent(s):
a82bbd1
more comet
Browse files- src/streamlit_app.py +8 -4
src/streamlit_app.py
CHANGED
|
@@ -103,16 +103,20 @@ def get_chat_completion_openai(client, prompt: str):
|
|
| 103 |
)
|
| 104 |
|
| 105 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
if query:
|
| 107 |
with st.spinner("Searching medical cases..."):
|
| 108 |
text_embeddings = embed_texts(data[TEXT_COLUMN])
|
| 109 |
query_embedding = embed_texts([query])[0]
|
| 110 |
|
| 111 |
# Compute similarity
|
| 112 |
-
|
| 113 |
-
top_result = torch.topk(cos_scores, k=1)
|
| 114 |
-
idx = top_result.indices[0].item()
|
| 115 |
-
selected = data[idx]
|
| 116 |
|
| 117 |
# Show Image
|
| 118 |
st.image(selected['image'], caption="Most relevant medical image", use_container_width=True)
|
|
|
|
| 103 |
)
|
| 104 |
|
| 105 |
|
| 106 |
+
def get_similar_prompt(query_embedding, text_embeddings):
|
| 107 |
+
cos_scores = util.pytorch_cos_sim(query_embedding, text_embeddings)[0]
|
| 108 |
+
top_result = torch.topk(cos_scores, k=1)
|
| 109 |
+
idx = top_result.indices[0].item()
|
| 110 |
+
return data[idx]
|
| 111 |
+
|
| 112 |
+
|
| 113 |
if query:
|
| 114 |
with st.spinner("Searching medical cases..."):
|
| 115 |
text_embeddings = embed_texts(data[TEXT_COLUMN])
|
| 116 |
query_embedding = embed_texts([query])[0]
|
| 117 |
|
| 118 |
# Compute similarity
|
| 119 |
+
selected = get_similar_prompt(query_embedding, text_embeddings)
|
|
|
|
|
|
|
|
|
|
| 120 |
|
| 121 |
# Show Image
|
| 122 |
st.image(selected['image'], caption="Most relevant medical image", use_container_width=True)
|