Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,7 @@
|
|
1 |
-
# Step 1: Import the necessary toolkits
|
2 |
import gradio as gr
|
3 |
from transformers import pipeline
|
4 |
|
5 |
-
# Step
|
6 |
print("Loading the Health Analysis model...")
|
7 |
health_classifier = pipeline(
|
8 |
"text-classification",
|
@@ -10,25 +9,18 @@ health_classifier = pipeline(
|
|
10 |
)
|
11 |
print("Model loaded successfully!")
|
12 |
|
13 |
-
#
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
'label_26': 'Common Cold', 'label_27': 'Pneumonia', 'label_28': 'Dimorphic hemmorhoids(piles)',
|
26 |
-
'label_29': 'Heart attack', 'label_30': 'Varicose veins', 'label_31': 'Hypothyroidism',
|
27 |
-
'label_32': 'Hyperthyroidism', 'label_33': 'Hypoglycemia', 'label_34': 'Osteoarthristis',
|
28 |
-
'label_35': 'Arthritis', 'label_36': '(vertigo) Paroymsal Positional Vertigo',
|
29 |
-
'label_37': 'Acne', 'label_38': 'Urinary tract infection', 'label_39': 'Psoriasis',
|
30 |
-
'label_40': 'Impetigo'
|
31 |
-
}
|
32 |
|
33 |
# Step 3: Define the content for our app
|
34 |
app_title = "Symptom to Disease Classifier"
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# Step 1: Load our AI Model
|
5 |
print("Loading the Health Analysis model...")
|
6 |
health_classifier = pipeline(
|
7 |
"text-classification",
|
|
|
9 |
)
|
10 |
print("Model loaded successfully!")
|
11 |
|
12 |
+
# Step 2: Define the main function for the app
|
13 |
+
def analyze_symptoms(symptoms):
|
14 |
+
# The pipeline returns a list containing one dictionary, e.g., [{'label': 'Allergy', 'score': 0.98}]
|
15 |
+
# We select the first item from the list to get the dictionary.
|
16 |
+
prediction_dict = health_classifier(symptoms)[0]
|
17 |
+
|
18 |
+
# Extract the disease name and score from the dictionary.
|
19 |
+
disease = prediction_dict['label']
|
20 |
+
confidence_score = prediction_dict['score']
|
21 |
+
|
22 |
+
# Format the results into a clean, readable string for the user.
|
23 |
+
return f"Predicted Condition: {disease}\nConfidence Score: {confidence_score:.2f}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
# Step 3: Define the content for our app
|
26 |
app_title = "Symptom to Disease Classifier"
|