Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -24,7 +24,7 @@ db_path = os.path.join(os.getcwd(), db_filename)
|
|
24 |
if not os.path.exists(db_path):
|
25 |
db_path = hf_hub_download(repo_id=db_repo, filename=db_filename, repo_type="dataset", use_auth_token=HF_TOKEN)
|
26 |
|
27 |
-
def find_best_hpo_match(finding, region):
|
28 |
"""Finds the best HPO match using semantic similarity."""
|
29 |
query_text = f"{finding} in {region}"
|
30 |
query_embedding = embedder.encode(query_text)
|
@@ -44,7 +44,7 @@ def find_best_hpo_match(finding, region):
|
|
44 |
best_match = {"hpo_id": hpo_id, "hpo_term": hpo_name}
|
45 |
|
46 |
conn.close()
|
47 |
-
return best_match if best_score >
|
48 |
|
49 |
|
50 |
def get_genes_for_hpo(hpo_id):
|
@@ -57,9 +57,9 @@ def get_genes_for_hpo(hpo_id):
|
|
57 |
return result[0].split(", ") if result else []
|
58 |
|
59 |
|
60 |
-
def get_hpo_for_finding(finding, region):
|
61 |
"""Finds the best HPO term and retrieves associated genes."""
|
62 |
-
hpo_match = find_best_hpo_match(finding, region)
|
63 |
if hpo_match:
|
64 |
hpo_match["genes"] = get_genes_for_hpo(hpo_match["hpo_id"])
|
65 |
else:
|
@@ -67,28 +67,36 @@ def get_hpo_for_finding(finding, region):
|
|
67 |
return hpo_match
|
68 |
|
69 |
|
70 |
-
def hpo_mapper_ui(finding, region):
|
71 |
"""Function for Gradio UI to get HPO mappings."""
|
72 |
if not finding or not region:
|
73 |
return "Please enter both finding and region.", "", ""
|
74 |
|
75 |
-
result = get_hpo_for_finding(finding, region)
|
76 |
return result["hpo_id"], result["hpo_term"], ", ".join(result["genes"])
|
77 |
|
78 |
# Create Gradio UI
|
79 |
demo = gr.Interface(
|
80 |
fn=hpo_mapper_ui,
|
81 |
-
inputs=[
|
|
|
|
|
|
|
|
|
82 |
outputs=[
|
83 |
gr.Textbox(label="HPO ID"),
|
84 |
gr.Textbox(label="HPO Term"),
|
85 |
gr.Textbox(label="Associated Genes")
|
86 |
],
|
87 |
title="HPO Mapper",
|
88 |
-
description=
|
89 |
-
|
90 |
-
|
|
|
|
|
|
|
|
|
91 |
)
|
92 |
|
93 |
if __name__ == "__main__":
|
94 |
-
demo.launch()
|
|
|
24 |
if not os.path.exists(db_path):
|
25 |
db_path = hf_hub_download(repo_id=db_repo, filename=db_filename, repo_type="dataset", use_auth_token=HF_TOKEN)
|
26 |
|
27 |
+
def find_best_hpo_match(finding, region, threshold):
|
28 |
"""Finds the best HPO match using semantic similarity."""
|
29 |
query_text = f"{finding} in {region}"
|
30 |
query_embedding = embedder.encode(query_text)
|
|
|
44 |
best_match = {"hpo_id": hpo_id, "hpo_term": hpo_name}
|
45 |
|
46 |
conn.close()
|
47 |
+
return best_match if best_score > threshold else None # Adjust threshold based on user input
|
48 |
|
49 |
|
50 |
def get_genes_for_hpo(hpo_id):
|
|
|
57 |
return result[0].split(", ") if result else []
|
58 |
|
59 |
|
60 |
+
def get_hpo_for_finding(finding, region, threshold):
|
61 |
"""Finds the best HPO term and retrieves associated genes."""
|
62 |
+
hpo_match = find_best_hpo_match(finding, region, threshold)
|
63 |
if hpo_match:
|
64 |
hpo_match["genes"] = get_genes_for_hpo(hpo_match["hpo_id"])
|
65 |
else:
|
|
|
67 |
return hpo_match
|
68 |
|
69 |
|
70 |
+
def hpo_mapper_ui(finding, region, threshold):
|
71 |
"""Function for Gradio UI to get HPO mappings."""
|
72 |
if not finding or not region:
|
73 |
return "Please enter both finding and region.", "", ""
|
74 |
|
75 |
+
result = get_hpo_for_finding(finding, region, threshold)
|
76 |
return result["hpo_id"], result["hpo_term"], ", ".join(result["genes"])
|
77 |
|
78 |
# Create Gradio UI
|
79 |
demo = gr.Interface(
|
80 |
fn=hpo_mapper_ui,
|
81 |
+
inputs=[
|
82 |
+
gr.Textbox(label="Finding"),
|
83 |
+
gr.Textbox(label="Region"),
|
84 |
+
gr.Slider(minimum=0.5, maximum=1.0, step=0.01, value=0.74, label="Threshold")
|
85 |
+
],
|
86 |
outputs=[
|
87 |
gr.Textbox(label="HPO ID"),
|
88 |
gr.Textbox(label="HPO Term"),
|
89 |
gr.Textbox(label="Associated Genes")
|
90 |
],
|
91 |
title="HPO Mapper",
|
92 |
+
description=(
|
93 |
+
"Enter a clinical finding and anatomical region to get the best-matching HPO term and associated genes.\n\n"
|
94 |
+
"### Reference:\n"
|
95 |
+
"**Application of Generative Artificial Intelligence to Utilise Unstructured Clinical Data for Acceleration of Inflammatory Bowel Disease Research**\n"
|
96 |
+
"Alex Z Kadhim, Zachary Green, Iman Nazari, Jonathan Baker, Michael George, Ashley Heinson, Matt Stammers, Christopher Kipps, R Mark Beattie, James J Ashton, Sarah Ennis\n"
|
97 |
+
"medRxiv 2025.03.07.25323569; [DOI: 10.1101/2025.03.07.25323569](https://doi.org/10.1101/2025.03.07.25323569)"
|
98 |
+
)
|
99 |
)
|
100 |
|
101 |
if __name__ == "__main__":
|
102 |
+
demo.launch()
|