Spaces:
No application file
No application file
Update app.py
Browse files
app.py
CHANGED
@@ -13,7 +13,16 @@ def load_data():
|
|
13 |
|
14 |
# Encode diseases
|
15 |
disease_dict = {
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
}
|
18 |
|
19 |
df.replace({'prognosis': disease_dict}, inplace=True)
|
@@ -24,7 +33,6 @@ def load_data():
|
|
24 |
|
25 |
return df, tr, disease_dict
|
26 |
|
27 |
-
# Try loading the data and handle exceptions
|
28 |
try:
|
29 |
df, tr, disease_dict = load_data()
|
30 |
except FileNotFoundError as e:
|
@@ -62,15 +70,15 @@ def predict_disease(model, symptoms):
|
|
62 |
prediction = model.predict([input_test])[0]
|
63 |
return list(disease_dict.keys())[list(disease_dict.values()).index(prediction)]
|
64 |
|
65 |
-
#
|
66 |
def app_function(name, symptom1, symptom2, symptom3, symptom4, symptom5):
|
67 |
if not name.strip():
|
68 |
-
return
|
69 |
|
70 |
symptoms_selected = [s for s in [symptom1, symptom2, symptom3, symptom4, symptom5] if s != "None"]
|
71 |
|
72 |
if len(symptoms_selected) < 3:
|
73 |
-
return
|
74 |
|
75 |
results = []
|
76 |
for model_name, (model, acc) in trained_models.items():
|
@@ -79,9 +87,9 @@ def app_function(name, symptom1, symptom2, symptom3, symptom4, symptom5):
|
|
79 |
result += f" (Accuracy: {acc * 100:.2f}%)"
|
80 |
results.append(result)
|
81 |
|
82 |
-
return results
|
83 |
|
84 |
-
# Gradio Interface
|
85 |
iface = gr.Interface(
|
86 |
fn=app_function,
|
87 |
inputs=[
|
@@ -90,12 +98,12 @@ iface = gr.Interface(
|
|
90 |
gr.Dropdown(["None"] + l1, label="Symptom 2"),
|
91 |
gr.Dropdown(["None"] + l1, label="Symptom 3"),
|
92 |
gr.Dropdown(["None"] + l1, label="Symptom 4"),
|
93 |
-
gr.Dropdown(["None"] + l1, label="Symptom 5")
|
94 |
],
|
95 |
outputs=gr.Textbox(label="Prediction"),
|
96 |
title="Disease Predictor Using Machine Learning",
|
97 |
description="For accurate results, please select at least 3 symptoms.",
|
98 |
-
|
99 |
)
|
100 |
|
101 |
# Launch the Gradio application
|
|
|
13 |
|
14 |
# Encode diseases
|
15 |
disease_dict = {
|
16 |
+
'Fungal infection': 0, 'Allergy': 1, 'GERD': 2, 'Chronic cholestasis': 3, 'Drug Reaction': 4,
|
17 |
+
'Peptic ulcer diseae': 5, 'AIDS': 6, 'Diabetes ': 7, 'Gastroenteritis': 8, 'Bronchial Asthma': 9,
|
18 |
+
'Hypertension ': 10, 'Migraine': 11, 'Cervical spondylosis': 12, 'Paralysis (brain hemorrhage)': 13,
|
19 |
+
'Jaundice': 14, 'Malaria': 15, 'Chicken pox': 16, 'Dengue': 17, 'Typhoid': 18, 'hepatitis A': 19,
|
20 |
+
'Hepatitis B': 20, 'Hepatitis C': 21, 'Hepatitis D': 22, 'Hepatitis E': 23, 'Alcoholic hepatitis': 24,
|
21 |
+
'Tuberculosis': 25, 'Common Cold': 26, 'Pneumonia': 27, 'Dimorphic hemmorhoids(piles)': 28,
|
22 |
+
'Heart attack': 29, 'Varicose veins': 30, 'Hypothyroidism': 31, 'Hyperthyroidism': 32,
|
23 |
+
'Hypoglycemia': 33, 'Osteoarthristis': 34, 'Arthritis': 35,
|
24 |
+
'(vertigo) Paroymsal Positional Vertigo': 36, 'Acne': 37, 'Urinary tract infection': 38,
|
25 |
+
'Psoriasis': 39, 'Impetigo': 40
|
26 |
}
|
27 |
|
28 |
df.replace({'prognosis': disease_dict}, inplace=True)
|
|
|
33 |
|
34 |
return df, tr, disease_dict
|
35 |
|
|
|
36 |
try:
|
37 |
df, tr, disease_dict = load_data()
|
38 |
except FileNotFoundError as e:
|
|
|
70 |
prediction = model.predict([input_test])[0]
|
71 |
return list(disease_dict.keys())[list(disease_dict.values()).index(prediction)]
|
72 |
|
73 |
+
# Gradio Interface
|
74 |
def app_function(name, symptom1, symptom2, symptom3, symptom4, symptom5):
|
75 |
if not name.strip():
|
76 |
+
return "Please enter the patient's name."
|
77 |
|
78 |
symptoms_selected = [s for s in [symptom1, symptom2, symptom3, symptom4, symptom5] if s != "None"]
|
79 |
|
80 |
if len(symptoms_selected) < 3:
|
81 |
+
return "Please select at least 3 symptoms for accurate prediction."
|
82 |
|
83 |
results = []
|
84 |
for model_name, (model, acc) in trained_models.items():
|
|
|
87 |
result += f" (Accuracy: {acc * 100:.2f}%)"
|
88 |
results.append(result)
|
89 |
|
90 |
+
return "\n\n".join(results)
|
91 |
|
92 |
+
# Gradio Interface Setup
|
93 |
iface = gr.Interface(
|
94 |
fn=app_function,
|
95 |
inputs=[
|
|
|
98 |
gr.Dropdown(["None"] + l1, label="Symptom 2"),
|
99 |
gr.Dropdown(["None"] + l1, label="Symptom 3"),
|
100 |
gr.Dropdown(["None"] + l1, label="Symptom 4"),
|
101 |
+
gr.Dropdown(["None"] + l1, label="Symptom 5"),
|
102 |
],
|
103 |
outputs=gr.Textbox(label="Prediction"),
|
104 |
title="Disease Predictor Using Machine Learning",
|
105 |
description="For accurate results, please select at least 3 symptoms.",
|
106 |
+
article="**Caution:** This system is designed for informational purposes only. Please visit a healthcare provider for any medical concerns."
|
107 |
)
|
108 |
|
109 |
# Launch the Gradio application
|