Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -60,23 +60,31 @@ def load_data():
|
|
60 |
except FileNotFoundError:
|
61 |
raise RuntimeError("Data files not found. Please ensure `Training.csv` and `Testing.csv` are uploaded correctly.")
|
62 |
|
|
|
63 |
disease_dict = {
|
64 |
'Fungal infection': 0, 'Allergy': 1, 'GERD': 2, 'Chronic cholestasis': 3, 'Drug Reaction': 4,
|
65 |
'Peptic ulcer diseae': 5, 'AIDS': 6, 'Diabetes': 7, 'Gastroenteritis': 8, 'Bronchial Asthma': 9,
|
66 |
-
'Hypertension': 10, 'Migraine': 11, 'Cervical spondylosis': 12, 'Paralysis': 13,
|
67 |
-
'Jaundice': 14, 'Malaria': 15, 'Chicken pox': 16, 'Dengue': 17, 'Typhoid': 18,
|
68 |
-
'Hepatitis
|
69 |
-
'
|
70 |
-
'Heart attack':
|
71 |
-
'Hypoglycemia':
|
|
|
|
|
72 |
}
|
73 |
|
74 |
# Replace prognosis values with numerical categories
|
75 |
df.replace({'prognosis': disease_dict}, inplace=True)
|
76 |
-
|
|
|
|
|
|
|
|
|
77 |
|
78 |
tr.replace({'prognosis': disease_dict}, inplace=True)
|
79 |
-
tr = tr.
|
|
|
80 |
|
81 |
return df, tr, disease_dict
|
82 |
|
@@ -87,9 +95,9 @@ y = df['prognosis']
|
|
87 |
X_test = tr[l1]
|
88 |
y_test = tr['prognosis']
|
89 |
|
90 |
-
# Encode the target variable
|
91 |
le = LabelEncoder()
|
92 |
-
y_encoded = le.fit_transform(y) #
|
93 |
|
94 |
def train_models():
|
95 |
models = {
|
@@ -186,7 +194,7 @@ def detect_emotion(user_input):
|
|
186 |
def generate_suggestions(emotion):
|
187 |
emotion_key = emotion.lower()
|
188 |
suggestions = {
|
189 |
-
#
|
190 |
}
|
191 |
|
192 |
formatted_suggestions = [
|
|
|
60 |
except FileNotFoundError:
|
61 |
raise RuntimeError("Data files not found. Please ensure `Training.csv` and `Testing.csv` are uploaded correctly.")
|
62 |
|
63 |
+
# Encode diseases
|
64 |
disease_dict = {
|
65 |
'Fungal infection': 0, 'Allergy': 1, 'GERD': 2, 'Chronic cholestasis': 3, 'Drug Reaction': 4,
|
66 |
'Peptic ulcer diseae': 5, 'AIDS': 6, 'Diabetes': 7, 'Gastroenteritis': 8, 'Bronchial Asthma': 9,
|
67 |
+
'Hypertension': 10, 'Migraine': 11, 'Cervical spondylosis': 12, 'Paralysis (brain hemorrhage)': 13,
|
68 |
+
'Jaundice': 14, 'Malaria': 15, 'Chicken pox': 16, 'Dengue': 17, 'Typhoid': 18, 'Hepatitis A': 19,
|
69 |
+
'Hepatitis B': 20, 'Hepatitis C': 21, 'Hepatitis D': 22, 'Hepatitis E': 23, 'Alcoholic hepatitis': 24,
|
70 |
+
'Tuberculosis': 25, 'Common Cold': 26, 'Pneumonia': 27, 'Dimorphic hemorrhoids(piles)': 28,
|
71 |
+
'Heart attack': 29, 'Varicose veins': 30, 'Hypothyroidism': 31, 'Hyperthyroidism': 32,
|
72 |
+
'Hypoglycemia': 33, 'Osteoarthritis': 34, 'Arthritis': 35,
|
73 |
+
'(vertigo) Paroxysmal Positional Vertigo': 36, 'Acne': 37, 'Urinary tract infection': 38,
|
74 |
+
'Psoriasis': 39, 'Impetigo': 40
|
75 |
}
|
76 |
|
77 |
# Replace prognosis values with numerical categories
|
78 |
df.replace({'prognosis': disease_dict}, inplace=True)
|
79 |
+
|
80 |
+
# Ensure prognosis is purely numerical after mapping
|
81 |
+
df['prognosis'] = df['prognosis'].astype(int) # Convert to integer if necessary
|
82 |
+
|
83 |
+
df = df.infer_objects() # Removed 'copy' argument
|
84 |
|
85 |
tr.replace({'prognosis': disease_dict}, inplace=True)
|
86 |
+
tr['prognosis'] = tr['prognosis'].astype(int) # Ensure it is also numerical
|
87 |
+
tr = tr.infer_objects() # Remove 'copy' argument
|
88 |
|
89 |
return df, tr, disease_dict
|
90 |
|
|
|
95 |
X_test = tr[l1]
|
96 |
y_test = tr['prognosis']
|
97 |
|
98 |
+
# Encode the target variable with LabelEncoder if not already numerical
|
99 |
le = LabelEncoder()
|
100 |
+
y_encoded = le.fit_transform(y) # Needs to be string labels, assuming df['prognosis'] has no numerical labels
|
101 |
|
102 |
def train_models():
|
103 |
models = {
|
|
|
194 |
def generate_suggestions(emotion):
|
195 |
emotion_key = emotion.lower()
|
196 |
suggestions = {
|
197 |
+
# Define suggestions based on the emotion detected
|
198 |
}
|
199 |
|
200 |
formatted_suggestions = [
|