Saintadlexx commited on
Commit
fc51b5a
·
verified ·
1 Parent(s): 7ce35a7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -21
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 2: Load our AI Model
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
- # NEW: Step 2.5 - Create the Label Dictionary
14
- # The model outputs generic names like 'label_0'. This dictionary maps them to real disease names.
15
- label_map = {
16
- 'label_0': 'Fungal infection', 'label_1': 'Allergy', 'label_2': 'GERD',
17
- 'label_3': 'Chronic cholestasis', 'label_4': 'Drug Reaction', 'label_5': 'Peptic ulcer disease',
18
- 'label_6': 'AIDS', 'label_7': 'Diabetes', 'label_8': 'Gastroenteritis',
19
- 'label_9': 'Bronchial Asthma', 'label_10': 'Hypertension', 'label_11': 'Migraine',
20
- 'label_12': 'Cervical spondylosis', 'label_13': 'Paralysis (brain hemorrhage)',
21
- 'label_14': 'Jaundice', 'label_15': 'Malaria', 'label_16': 'Chicken pox',
22
- 'label_17': 'Dengue', 'label_18': 'Typhoid', 'label_19': 'Hepatitis A',
23
- 'label_20': 'Hepatitis B', 'label_21': 'Hepatitis C', 'label_22': 'Hepatitis D',
24
- 'label_23': 'Hepatitis E', 'label_24': 'Alcoholic hepatitis', 'label_25': 'Tuberculosis',
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"