Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Check SNOMED CT description is FSN
Browse filesCheck SNOMED CT description is FSN (contain the parentheses "(" & ")" )
- SNOMED-CT_Assistant.py +7 -3
SNOMED-CT_Assistant.py
CHANGED
|
@@ -127,7 +127,7 @@ def generate_entity_mapping_prompt(entity, query_result_dict):
|
|
| 127 |
def query_chroma_db(query_text, query_number):
|
| 128 |
results = collection.query(
|
| 129 |
query_texts=[query_text],
|
| 130 |
-
n_results=query_number,
|
| 131 |
include=["distances", "metadatas", "documents"]
|
| 132 |
)
|
| 133 |
return results
|
|
@@ -156,12 +156,12 @@ def chat_input(prompt, med_text):
|
|
| 156 |
for entity in entity_list:
|
| 157 |
results = query_chroma_db(entity, query_number)
|
| 158 |
results_dict = get_dict_from_chroma_results(results)
|
| 159 |
-
results_table = entity_mapping_result_to_table(entity, results_dict)
|
| 160 |
st.session_state.messages.append({"role": "assistant", "content": results_table})
|
| 161 |
st.chat_message("assistant").write(results_table)
|
| 162 |
|
| 163 |
# Conver entity mapping result to markdown table
|
| 164 |
-
def entity_mapping_result_to_table(entity, results_dict):
|
| 165 |
|
| 166 |
ids = results_dict['ids']
|
| 167 |
concept_ids = results_dict['concept_ids']
|
|
@@ -175,8 +175,12 @@ def entity_mapping_result_to_table(entity, results_dict):
|
|
| 175 |
# table
|
| 176 |
rows = []
|
| 177 |
for id, distance, concept_id, description in zip(ids, distances, concept_ids, descriptions):
|
|
|
|
|
|
|
| 178 |
row = f"| {entity} | {distance:.3f} | {id} | {concept_id} | {description} |"
|
| 179 |
rows.append(row)
|
|
|
|
|
|
|
| 180 |
|
| 181 |
# merge
|
| 182 |
markdown_table = "\n".join([header, seperator] + rows)
|
|
|
|
| 127 |
def query_chroma_db(query_text, query_number):
|
| 128 |
results = collection.query(
|
| 129 |
query_texts=[query_text],
|
| 130 |
+
n_results=query_number+20,
|
| 131 |
include=["distances", "metadatas", "documents"]
|
| 132 |
)
|
| 133 |
return results
|
|
|
|
| 156 |
for entity in entity_list:
|
| 157 |
results = query_chroma_db(entity, query_number)
|
| 158 |
results_dict = get_dict_from_chroma_results(results)
|
| 159 |
+
results_table = entity_mapping_result_to_table(entity, results_dict, query_number)
|
| 160 |
st.session_state.messages.append({"role": "assistant", "content": results_table})
|
| 161 |
st.chat_message("assistant").write(results_table)
|
| 162 |
|
| 163 |
# Conver entity mapping result to markdown table
|
| 164 |
+
def entity_mapping_result_to_table(entity, results_dict, query_number):
|
| 165 |
|
| 166 |
ids = results_dict['ids']
|
| 167 |
concept_ids = results_dict['concept_ids']
|
|
|
|
| 175 |
# table
|
| 176 |
rows = []
|
| 177 |
for id, distance, concept_id, description in zip(ids, distances, concept_ids, descriptions):
|
| 178 |
+
if '(' not in description or ')' not in description:
|
| 179 |
+
continue
|
| 180 |
row = f"| {entity} | {distance:.3f} | {id} | {concept_id} | {description} |"
|
| 181 |
rows.append(row)
|
| 182 |
+
if len(rows) >= query_number:
|
| 183 |
+
break
|
| 184 |
|
| 185 |
# merge
|
| 186 |
markdown_table = "\n".join([header, seperator] + rows)
|