Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,10 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
# Load a
|
| 5 |
-
model = pipeline("zero-shot-classification", model="
|
| 6 |
|
| 7 |
-
#
|
| 8 |
candidate_labels = [
|
| 9 |
"respiratory infection", "viral infection", "bacterial infection", "autoimmune disease",
|
| 10 |
"cardiovascular disease", "endocrine disorders", "gastrointestinal disorders",
|
|
@@ -16,14 +16,28 @@ def diagnose(symptoms):
|
|
| 16 |
result = model(symptoms, candidate_labels=candidate_labels)
|
| 17 |
diagnosis_category = result['labels'][0] # Top predicted category
|
| 18 |
confidence = result['scores'][0] # Confidence score
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
return f"Predicted diagnosis category: {diagnosis_category} with confidence: {confidence:.2f}"
|
| 20 |
|
| 21 |
# Triage function to assess symptom severity
|
| 22 |
def triage(symptoms):
|
|
|
|
| 23 |
if "shortness of breath" in symptoms or "chest pain" in symptoms:
|
| 24 |
return "Urgent: Seek immediate medical attention."
|
|
|
|
|
|
|
| 25 |
elif "fever" in symptoms and "cough" in symptoms:
|
| 26 |
return "Mild: Likely a viral infection, monitor symptoms."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
else:
|
| 28 |
return "Non-urgent: No immediate concern."
|
| 29 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Load a more suitable model for medical diagnosis (BioBERT)
|
| 5 |
+
model = pipeline("zero-shot-classification", model="dmis-lab/biobert-base-cased-v1.1")
|
| 6 |
|
| 7 |
+
# Candidate labels for medical diagnosis
|
| 8 |
candidate_labels = [
|
| 9 |
"respiratory infection", "viral infection", "bacterial infection", "autoimmune disease",
|
| 10 |
"cardiovascular disease", "endocrine disorders", "gastrointestinal disorders",
|
|
|
|
| 16 |
result = model(symptoms, candidate_labels=candidate_labels)
|
| 17 |
diagnosis_category = result['labels'][0] # Top predicted category
|
| 18 |
confidence = result['scores'][0] # Confidence score
|
| 19 |
+
|
| 20 |
+
# Only accept predictions with confidence >= 0.60
|
| 21 |
+
if confidence < 0.60:
|
| 22 |
+
return "Unable to provide a confident diagnosis. Please consult a healthcare professional."
|
| 23 |
+
|
| 24 |
return f"Predicted diagnosis category: {diagnosis_category} with confidence: {confidence:.2f}"
|
| 25 |
|
| 26 |
# Triage function to assess symptom severity
|
| 27 |
def triage(symptoms):
|
| 28 |
+
# Check for critical symptoms that need urgent attention
|
| 29 |
if "shortness of breath" in symptoms or "chest pain" in symptoms:
|
| 30 |
return "Urgent: Seek immediate medical attention."
|
| 31 |
+
|
| 32 |
+
# Check for milder symptoms
|
| 33 |
elif "fever" in symptoms and "cough" in symptoms:
|
| 34 |
return "Mild: Likely a viral infection, monitor symptoms."
|
| 35 |
+
|
| 36 |
+
# New logic for symptoms like "red nose and cheeks"
|
| 37 |
+
elif "red nose" in symptoms or "red cheeks" in symptoms:
|
| 38 |
+
return "Non-urgent: Likely a mild skin reaction. Monitor for any additional symptoms."
|
| 39 |
+
|
| 40 |
+
# Default case if no specific symptoms are detected
|
| 41 |
else:
|
| 42 |
return "Non-urgent: No immediate concern."
|
| 43 |
|