Spaces:
Sleeping
Sleeping
jocko
commited on
Commit
·
9ea931a
1
Parent(s):
61e5bfd
merge code
Browse files- src/streamlit_app.py +6 -4
src/streamlit_app.py
CHANGED
|
@@ -118,7 +118,10 @@ def get_chat_completion_openai(client, prompt: str):
|
|
| 118 |
)
|
| 119 |
|
| 120 |
@track
|
| 121 |
-
def get_similar_prompt(
|
|
|
|
|
|
|
|
|
|
| 122 |
cos_scores = util.pytorch_cos_sim(query_embedding, text_embeddings)[0]
|
| 123 |
top_result = torch.topk(cos_scores, k=1)
|
| 124 |
idx = top_result.indices[0].item()
|
|
@@ -127,11 +130,10 @@ def get_similar_prompt(query_embedding, text_embeddings):
|
|
| 127 |
|
| 128 |
if query:
|
| 129 |
with st.spinner("Searching medical cases..."):
|
| 130 |
-
|
| 131 |
-
query_embedding = embed_query_text(query) # recalculated each time
|
| 132 |
|
| 133 |
# Compute similarity
|
| 134 |
-
selected = get_similar_prompt(
|
| 135 |
|
| 136 |
# Show Image
|
| 137 |
st.image(selected['image'], caption="Most relevant medical image", use_container_width=True)
|
|
|
|
| 118 |
)
|
| 119 |
|
| 120 |
@track
|
| 121 |
+
def get_similar_prompt(query):
|
| 122 |
+
text_embeddings = embed_dataset_texts(combined_texts) # cached
|
| 123 |
+
query_embedding = embed_query_text(query) # recalculated each time
|
| 124 |
+
|
| 125 |
cos_scores = util.pytorch_cos_sim(query_embedding, text_embeddings)[0]
|
| 126 |
top_result = torch.topk(cos_scores, k=1)
|
| 127 |
idx = top_result.indices[0].item()
|
|
|
|
| 130 |
|
| 131 |
if query:
|
| 132 |
with st.spinner("Searching medical cases..."):
|
| 133 |
+
|
|
|
|
| 134 |
|
| 135 |
# Compute similarity
|
| 136 |
+
selected = get_similar_prompt(combined_texts, query)
|
| 137 |
|
| 138 |
# Show Image
|
| 139 |
st.image(selected['image'], caption="Most relevant medical image", use_container_width=True)
|