Spaces:
Sleeping
Sleeping
Update snomed ct vector database with fullname.
Browse files- SNOMED-CT_Assistant.py +6 -16
- pages/Vector DB of SNOMED-CT.py +4 -4
- snomed_ct_id_term_fullname_634k/a2d80cd0-644c-48f7-baf2-fb9cc743736e/data_level0.bin +3 -0
- snomed_ct_id_term_fullname_634k/a2d80cd0-644c-48f7-baf2-fb9cc743736e/header.bin +3 -0
- snomed_ct_id_term_fullname_634k/a2d80cd0-644c-48f7-baf2-fb9cc743736e/index_metadata.pickle +3 -0
- snomed_ct_id_term_fullname_634k/a2d80cd0-644c-48f7-baf2-fb9cc743736e/length.bin +3 -0
- snomed_ct_id_term_fullname_634k/a2d80cd0-644c-48f7-baf2-fb9cc743736e/link_lists.bin +3 -0
- snomed_ct_id_term_fullname_634k/chroma.sqlite3 +3 -0
SNOMED-CT_Assistant.py
CHANGED
@@ -25,6 +25,10 @@ st.title("🏥 SNOMED-CT Assistant")
|
|
25 |
st.caption("👩⚕️ A smart medical assistant with SNOMED-CT knowledge.")
|
26 |
query_number = st.sidebar.slider("Query Numbers", 5, 20, 5)
|
27 |
|
|
|
|
|
|
|
|
|
28 |
# System prompt
|
29 |
system_prompt = """You are a medical expert with rich experience in SNOMED-CT professional knowledge.
|
30 |
You are skilled at assisting medical professionals and answering questions in the medical field.
|
@@ -119,10 +123,6 @@ def generate_entity_identification_prompt(medical_text):
|
|
119 |
def generate_entity_mapping_prompt(entity, query_result_dict):
|
120 |
return f"""Help me to do "SNOMED-CT Entity Mapping" process with entity: {entity} and query result \n {query_result_dict} \n , output with table format, including 5 columns: "Identified Entity", "Distance", "IDs", "SNOMED CT Concept IDs", "SNOMED CT Descriptions" \n """
|
121 |
|
122 |
-
# Chroma DB Client
|
123 |
-
chroma_client = chromadb.PersistentClient(path="snomed_ct_id_term_1410k")
|
124 |
-
collection = chroma_client.get_or_create_collection(name="snomed_ct_id_term")
|
125 |
-
|
126 |
# Func: query chrome_db
|
127 |
def query_chroma_db(query_text, query_number):
|
128 |
results = collection.query(
|
@@ -160,16 +160,6 @@ def chat_input(prompt, med_text):
|
|
160 |
st.session_state.messages.append({"role": "assistant", "content": results_table})
|
161 |
st.chat_message("assistant").write(results_table)
|
162 |
|
163 |
-
|
164 |
-
# entity_mapping_prompt = generate_entity_mapping_prompt(entity, results_dict)
|
165 |
-
# st.session_state.messages.append({"role": "user", "content": entity_mapping_prompt})
|
166 |
-
# entity_mapping_response = client.chat.completions.create(
|
167 |
-
# model=model_tag, messages=st.session_state.messages, temperature=0.5)
|
168 |
-
# mapping_msg = entity_mapping_response.choices[0].message.content
|
169 |
-
# st.session_state.messages.append({"role": "assistant", "content": mapping_msg})
|
170 |
-
# st.chat_message("assistant").write(mapping_msg)
|
171 |
-
|
172 |
-
|
173 |
# Conver entity mapping result to markdown table
|
174 |
def entity_mapping_result_to_table(entity, results_dict):
|
175 |
|
@@ -179,7 +169,7 @@ def entity_mapping_result_to_table(entity, results_dict):
|
|
179 |
descriptions = results_dict['descriptions']
|
180 |
|
181 |
# header
|
182 |
-
header = "| Identified Entity | Distance | IDs | SNOMED CT - Concept IDs | SNOMED CT - Descriptions |"
|
183 |
seperator = "| --- | --- | --- | --- | --- |"
|
184 |
|
185 |
# table
|
@@ -196,7 +186,7 @@ def entity_mapping_result_to_table(entity, results_dict):
|
|
196 |
|
197 |
if "messages" not in st.session_state:
|
198 |
st.session_state["messages"] = [{"role": "system", "content": system_prompt},
|
199 |
-
{"role": "assistant", "content": "👩⚕️ 您好,我是您的專業醫學助理。請問有任何我可以協助你的地方嗎?"}]
|
200 |
|
201 |
for msg in st.session_state.messages:
|
202 |
if msg["role"] == "system":
|
|
|
25 |
st.caption("👩⚕️ A smart medical assistant with SNOMED-CT knowledge.")
|
26 |
query_number = st.sidebar.slider("Query Numbers", 5, 20, 5)
|
27 |
|
28 |
+
# Config Chroma DB Client
|
29 |
+
chroma_client = chromadb.PersistentClient(path="snomed_ct_id_term_fullname_634k")
|
30 |
+
collection = chroma_client.get_or_create_collection(name="snomed_ct_id_term_fullname")
|
31 |
+
|
32 |
# System prompt
|
33 |
system_prompt = """You are a medical expert with rich experience in SNOMED-CT professional knowledge.
|
34 |
You are skilled at assisting medical professionals and answering questions in the medical field.
|
|
|
123 |
def generate_entity_mapping_prompt(entity, query_result_dict):
|
124 |
return f"""Help me to do "SNOMED-CT Entity Mapping" process with entity: {entity} and query result \n {query_result_dict} \n , output with table format, including 5 columns: "Identified Entity", "Distance", "IDs", "SNOMED CT Concept IDs", "SNOMED CT Descriptions" \n """
|
125 |
|
|
|
|
|
|
|
|
|
126 |
# Func: query chrome_db
|
127 |
def query_chroma_db(query_text, query_number):
|
128 |
results = collection.query(
|
|
|
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 |
|
|
|
169 |
descriptions = results_dict['descriptions']
|
170 |
|
171 |
# header
|
172 |
+
header = "| Identified Entity | Distance | SNOMED CT - IDs | SNOMED CT - Concept IDs | SNOMED CT - Descriptions |"
|
173 |
seperator = "| --- | --- | --- | --- | --- |"
|
174 |
|
175 |
# table
|
|
|
186 |
|
187 |
if "messages" not in st.session_state:
|
188 |
st.session_state["messages"] = [{"role": "system", "content": system_prompt},
|
189 |
+
{"role": "assistant", "content": "👩⚕️ 您好,我是您的專業醫學助理。請問有任何我可以協助你的地方嗎? \n請在對話欄中輸入任意的英文電子病歷字串來測試,我會為您查詢其中相關字詞所對應的 SNOMED CT 術語。"}]
|
190 |
|
191 |
for msg in st.session_state.messages:
|
192 |
if msg["role"] == "system":
|
pages/Vector DB of SNOMED-CT.py
CHANGED
@@ -16,13 +16,13 @@ st.set_page_config(layout="wide")
|
|
16 |
st.title("📚 Semantic Search with Vector Database of SNOMED-CT 💡")
|
17 |
st.caption("🔍 Search any SNOMED-CT relate decription & concept with natural language.")
|
18 |
st.sidebar.title("🔍 Search Setting")
|
19 |
-
query_number = st.sidebar.slider("Query Numbers", 10,
|
20 |
st.markdown("##### ➡️⌨️ Please input some medical description here, e.g. \"insomnia two nights a week.\", \"COPD\", \"Degenerative Joint Disease\"")
|
21 |
query_text = st.text_input("Input: any medical description snippet","Type-2 Diabetes")
|
22 |
|
23 |
# Chroma DB Client
|
24 |
-
chroma_client = chromadb.PersistentClient(path="
|
25 |
-
collection = chroma_client.get_or_create_collection(name="
|
26 |
start = 1.0
|
27 |
end = 1.1
|
28 |
st.markdown("##### ➡️Chroma DB will return " + str(query_number)
|
@@ -55,5 +55,5 @@ results_df = get_df_from_chroma_results(results)
|
|
55 |
|
56 |
#displaying the dataframe as an interactive object
|
57 |
st.markdown("### 📊 Similar Search Results from Chroma Vector DB")
|
58 |
-
st.dataframe(results_df, 1000,
|
59 |
|
|
|
16 |
st.title("📚 Semantic Search with Vector Database of SNOMED-CT 💡")
|
17 |
st.caption("🔍 Search any SNOMED-CT relate decription & concept with natural language.")
|
18 |
st.sidebar.title("🔍 Search Setting")
|
19 |
+
query_number = st.sidebar.slider("Query Numbers", 10, 50, 10)
|
20 |
st.markdown("##### ➡️⌨️ Please input some medical description here, e.g. \"insomnia two nights a week.\", \"COPD\", \"Degenerative Joint Disease\"")
|
21 |
query_text = st.text_input("Input: any medical description snippet","Type-2 Diabetes")
|
22 |
|
23 |
# Chroma DB Client
|
24 |
+
chroma_client = chromadb.PersistentClient(path="snomed_ct_id_term_fullname_634k")
|
25 |
+
collection = chroma_client.get_or_create_collection(name="snomed_ct_id_term_fullname")
|
26 |
start = 1.0
|
27 |
end = 1.1
|
28 |
st.markdown("##### ➡️Chroma DB will return " + str(query_number)
|
|
|
55 |
|
56 |
#displaying the dataframe as an interactive object
|
57 |
st.markdown("### 📊 Similar Search Results from Chroma Vector DB")
|
58 |
+
st.dataframe(results_df, 1000, 800)
|
59 |
|
snomed_ct_id_term_fullname_634k/a2d80cd0-644c-48f7-baf2-fb9cc743736e/data_level0.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:373e7cdf5cdcfbd76e6f495c5ccd8a0946b68b16cf3a0dcaadfac3bf400e2bbb
|
3 |
+
size 1062584000
|
snomed_ct_id_term_fullname_634k/a2d80cd0-644c-48f7-baf2-fb9cc743736e/header.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:342f57a56758253455d6ffb709e1c568b07231d5cc56273f192ebd03bfb33435
|
3 |
+
size 100
|
snomed_ct_id_term_fullname_634k/a2d80cd0-644c-48f7-baf2-fb9cc743736e/index_metadata.pickle
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:863933654d8448809ffe8b4182a477727552693c363363bd5334e0be98383803
|
3 |
+
size 23398984
|
snomed_ct_id_term_fullname_634k/a2d80cd0-644c-48f7-baf2-fb9cc743736e/length.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c1316a43da7d1aa1c130242c0d5fef5929cd7c4dd88a52673ad0ed9c20e9008b
|
3 |
+
size 2536000
|
snomed_ct_id_term_fullname_634k/a2d80cd0-644c-48f7-baf2-fb9cc743736e/link_lists.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a1ad8d35c3daefb9706ec23d6da013ec64104ab7ac9889fe8471d13d24b97ea8
|
3 |
+
size 5403220
|
snomed_ct_id_term_fullname_634k/chroma.sqlite3
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:45ff1ea2b19c33b300cfd14ea27ce561662fd995bf7eb68e330f591e70b5d102
|
3 |
+
size 1641885696
|