Spaces:
Sleeping
Sleeping
ashishkgpian
commited on
create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load the model
|
5 |
+
classifier = pipeline(
|
6 |
+
"text-classification",
|
7 |
+
model="ashishkgpian/biolinkbert_base_icd9_classifier_ehr_symptoms_text_icd9_150_epochs"
|
8 |
+
)
|
9 |
+
|
10 |
+
def classify_symptoms(text):
|
11 |
+
"""
|
12 |
+
Classify medical symptoms and return top ICD9 codes
|
13 |
+
|
14 |
+
Args:
|
15 |
+
text (str): Input medical symptom description
|
16 |
+
|
17 |
+
Returns:
|
18 |
+
dict: Top classification results with ICD9 codes and probabilities
|
19 |
+
"""
|
20 |
+
try:
|
21 |
+
# Get classification results
|
22 |
+
results = classifier(text, top_k=5)
|
23 |
+
|
24 |
+
# Format results for more readable output
|
25 |
+
formatted_results = []
|
26 |
+
for result in results:
|
27 |
+
formatted_results.append({
|
28 |
+
"ICD9 Code": result['label'],
|
29 |
+
"Confidence": f"{result['score']:.2%}"
|
30 |
+
})
|
31 |
+
|
32 |
+
return formatted_results
|
33 |
+
|
34 |
+
except Exception as e:
|
35 |
+
return f"Error processing classification: {str(e)}"
|
36 |
+
|
37 |
+
# Create Gradio interface
|
38 |
+
demo = gr.Interface(
|
39 |
+
fn=classify_symptoms,
|
40 |
+
inputs=gr.Textbox(
|
41 |
+
label="Enter Medical Symptoms",
|
42 |
+
placeholder="Describe patient symptoms here..."
|
43 |
+
),
|
44 |
+
outputs=gr.JSON(label="Top 5 ICD9 Classifications"),
|
45 |
+
title="BioBERT ICD9 Symptom Classifier",
|
46 |
+
description="Classify medical symptoms into ICD9 diagnostic codes using a fine-tuned BioBERT model.",
|
47 |
+
theme="huggingface",
|
48 |
+
examples=[
|
49 |
+
["Patient experiencing chest pain and shortness of breath"],
|
50 |
+
["Recurring headaches with nausea"],
|
51 |
+
["Diabetic symptoms including frequent urination"]
|
52 |
+
]
|
53 |
+
)
|
54 |
+
|
55 |
+
if __name__ == "__main__":
|
56 |
+
demo.launch()
|