Saintadlexx commited on
Commit
773040f
·
verified ·
1 Parent(s): fc51b5a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -20
app.py CHANGED
@@ -1,7 +1,7 @@
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,33 +9,49 @@ health_classifier = pipeline(
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"
27
- app_description = """
28
- Enter a list of symptoms, and this AI will predict a possible related medical condition.
29
- This tool is for educational purposes only and is based on the 'shanover/disease_classifier_base' model from Hugging Face.
30
- """
31
- disclaimer = """
32
- **⚠️ IMPORTANT DISCLAIMER ⚠️**
33
- This is NOT a medical diagnostic tool. The predictions are generated by an AI model and may be inaccurate.
34
- **Always consult with a qualified healthcare professional for any medical advice or diagnosis.**
35
- This tool should not be used for any real-world medical decision-making.
36
- """
37
 
38
- # Step 4: Create and Launch the Gradio Web App Interface
39
  app = gr.Interface(
40
  fn=analyze_symptoms,
41
  inputs=gr.Textbox(
@@ -53,5 +69,4 @@ app = gr.Interface(
53
  ]
54
  )
55
 
56
- # Go live!
57
  app.launch()
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Step 1: Load the 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: Create the Label-to-Name Dictionary
13
+ # This is the translator that maps the model's output to real disease names.
14
+ label_map = {
15
+ 'LABEL_0': 'Fungal infection', 'LABEL_1': 'Allergy', 'LABEL_2': 'GERD',
16
+ 'LABEL_3': 'Chronic cholestasis', 'LABEL_4': 'Drug Reaction', 'LABEL_5': 'Peptic ulcer disease',
17
+ 'LABEL_6': 'AIDS', 'LABEL_7': 'Diabetes', 'LABEL_8': 'Gastroenteritis',
18
+ 'LABEL_9': 'Bronchial Asthma', 'LABEL_10': 'Hypertension', 'LABEL_11': 'Migraine',
19
+ 'LABEL_12': 'Cervical spondylosis', 'LABEL_13': 'Paralysis (brain hemorrhage)',
20
+ 'LABEL_14': 'Jaundice', 'LABEL_15': 'Malaria', 'LABEL_16': 'Chicken pox',
21
+ 'LABEL_17': 'Dengue', 'LABEL_18': 'Typhoid', 'LABEL_19': 'Hepatitis A',
22
+ 'LABEL_20': 'Hepatitis B', 'LABEL_21': 'Hepatitis C', 'LABEL_22': 'Hepatitis D',
23
+ 'LABEL_23': 'Hepatitis E', 'LABEL_24': 'Alcoholic hepatitis', 'LABEL_25': 'Tuberculosis',
24
+ 'LABEL_26': 'Common Cold', 'LABEL_27': 'Pneumonia', 'LABEL_28': 'Dimorphic hemmorhoids(piles)',
25
+ 'LABEL_29': 'Heart attack', 'LABEL_30': 'Varicose veins', 'LABEL_31': 'Hypothyroidism',
26
+ 'LABEL_32': 'Hyperthyroidism', 'LABEL_33': 'Hypoglycemia', 'LABEL_34': 'Osteoarthristis',
27
+ 'LABEL_35': 'Arthritis', 'LABEL_36': '(vertigo) Paroymsal Positional Vertigo',
28
+ 'LABEL_37': 'Acne', 'LABEL_38': 'Urinary tract infection', 'LABEL_39': 'Psoriasis',
29
+ 'LABEL_40': 'Impetigo'
30
+ }
31
+
32
+ # Step 3: Define the main analysis function
33
  def analyze_symptoms(symptoms):
34
+ # Get the prediction dictionary from the model, e.g., {'label': 'LABEL_2', 'score': 0.96}
 
35
  prediction_dict = health_classifier(symptoms)[0]
36
 
37
+ # Get the generic label (e.g., 'LABEL_2')
38
+ generic_label = prediction_dict['label']
39
+
40
+ # Look up the real disease name in our dictionary
41
+ disease = label_map.get(generic_label, "Unknown Condition")
42
+
43
+ # Get the confidence score
44
  confidence_score = prediction_dict['score']
45
 
46
+ # Format the final, clean string for the user
47
  return f"Predicted Condition: {disease}\nConfidence Score: {confidence_score:.2f}"
48
 
49
+ # Step 4: Define the app's text content
50
  app_title = "Symptom to Disease Classifier"
51
+ app_description = "Enter symptoms to predict a possible related medical condition. For educational use only."
52
+ disclaimer = "⚠️ **IMPORTANT DISCLAIMER:** This is NOT a medical diagnostic tool. Always consult a qualified healthcare professional for medical advice."
 
 
 
 
 
 
 
 
53
 
54
+ # Step 5: Create and Launch the Gradio Interface
55
  app = gr.Interface(
56
  fn=analyze_symptoms,
57
  inputs=gr.Textbox(
 
69
  ]
70
  )
71
 
 
72
  app.launch()