Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,76 +1,57 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
-
from sentence_transformers import SentenceTransformer, util
|
4 |
import numpy as np
|
5 |
|
6 |
-
#
|
7 |
-
|
8 |
-
MODEL_NAME = "d4data/biomedical-clinical-trials-bert"
|
9 |
CLASSES = [
|
10 |
"Cardiology", "Neurology", "Oncology", "Pediatrics",
|
11 |
"Orthopedics", "Dermatology", "Gastroenterology",
|
12 |
"Endocrinology", "Psychiatry", "Pulmonology"
|
13 |
]
|
14 |
|
15 |
-
#
|
16 |
-
EXAMPLES = {
|
17 |
-
"Cardiology": [
|
18 |
-
"chest pain", "shortness of breath", "palpitations",
|
19 |
-
"high blood pressure", "irregular heartbeat"
|
20 |
-
],
|
21 |
-
"Neurology": [
|
22 |
-
"headache", "dizziness", "numbness in limbs",
|
23 |
-
"seizures", "memory problems"
|
24 |
-
],
|
25 |
-
"Oncology": [
|
26 |
-
"unexplained weight loss", "persistent lumps",
|
27 |
-
"unusual bleeding", "chronic fatigue", "skin changes"
|
28 |
-
],
|
29 |
-
# Add more examples for other specialties...
|
30 |
-
}
|
31 |
-
|
32 |
-
# Initialize models
|
33 |
classifier = pipeline(
|
34 |
"text-classification",
|
35 |
-
model=
|
36 |
-
tokenizer=
|
37 |
)
|
38 |
-
embedder = SentenceTransformer('all-MiniLM-L6-v2')
|
39 |
|
40 |
def predict_specialty(symptoms):
|
41 |
"""
|
42 |
Predict the most relevant medical specialty based on symptoms.
|
43 |
-
|
44 |
"""
|
45 |
# Get classification prediction
|
46 |
pred = classifier(symptoms)
|
47 |
predicted_class = pred[0]['label']
|
48 |
|
49 |
-
#
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
57 |
|
58 |
-
|
59 |
-
|
60 |
-
for specialty in CLASSES:
|
61 |
-
class_score = 1.0 if specialty == predicted_class else 0.0
|
62 |
-
sim_score = similarities.get(specialty, 0.0)
|
63 |
-
combined_scores[specialty] = (class_score + sim_score) / 2
|
64 |
|
65 |
-
#
|
66 |
-
|
67 |
-
|
|
|
|
|
|
|
|
|
|
|
68 |
|
69 |
-
# Format output
|
70 |
result = {
|
71 |
-
"Primary Specialty":
|
72 |
-
"Confidence":
|
73 |
-
"Alternative Suggestions":
|
74 |
}
|
75 |
|
76 |
return result
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
|
|
3 |
import numpy as np
|
4 |
|
5 |
+
# Use a simpler approach that doesn't require sentence-transformers
|
6 |
+
MODEL_NAME = "samrawal/bert-base-uncased_clinical-ner"
|
|
|
7 |
CLASSES = [
|
8 |
"Cardiology", "Neurology", "Oncology", "Pediatrics",
|
9 |
"Orthopedics", "Dermatology", "Gastroenterology",
|
10 |
"Endocrinology", "Psychiatry", "Pulmonology"
|
11 |
]
|
12 |
|
13 |
+
# Initialize model
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
classifier = pipeline(
|
15 |
"text-classification",
|
16 |
+
model="bhadresh-savani/bert-base-uncased-emotion",
|
17 |
+
tokenizer="bhadresh-savani/bert-base-uncased-emotion"
|
18 |
)
|
|
|
19 |
|
20 |
def predict_specialty(symptoms):
|
21 |
"""
|
22 |
Predict the most relevant medical specialty based on symptoms.
|
23 |
+
Simplified version without sentence-transformers.
|
24 |
"""
|
25 |
# Get classification prediction
|
26 |
pred = classifier(symptoms)
|
27 |
predicted_class = pred[0]['label']
|
28 |
|
29 |
+
# Simple mapping - in a real app you'd want more sophisticated logic
|
30 |
+
specialty_map = {
|
31 |
+
'sadness': 'Psychiatry',
|
32 |
+
'joy': 'Pediatrics', # Just example mapping
|
33 |
+
'love': 'Cardiology',
|
34 |
+
'anger': 'Neurology',
|
35 |
+
'fear': 'Psychiatry',
|
36 |
+
'surprise': 'Emergency Medicine'
|
37 |
+
}
|
38 |
|
39 |
+
primary = specialty_map.get(predicted_class, "General Practice")
|
40 |
+
confidence = f"{pred[0]['score']*100:.1f}%"
|
|
|
|
|
|
|
|
|
41 |
|
42 |
+
# Simple alternative suggestions
|
43 |
+
alternatives = []
|
44 |
+
if primary == "Psychiatry":
|
45 |
+
alternatives = ["Neurology", "Endocrinology"]
|
46 |
+
elif primary == "Cardiology":
|
47 |
+
alternatives = ["Pulmonology", "Gastroenterology"]
|
48 |
+
else:
|
49 |
+
alternatives = ["General Practice", "Internal Medicine"]
|
50 |
|
|
|
51 |
result = {
|
52 |
+
"Primary Specialty": primary,
|
53 |
+
"Confidence": confidence,
|
54 |
+
"Alternative Suggestions": alternatives
|
55 |
}
|
56 |
|
57 |
return result
|