Spaces:
Sleeping
Sleeping
Commit
·
bdac973
1
Parent(s):
9795cc8
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,23 +13,29 @@ data = pd.read_csv('dataset.csv')
|
|
| 13 |
# Preprocess the dataset
|
| 14 |
mlb = MultiLabelBinarizer()
|
| 15 |
symptoms = [s.split(',') for s in data['Symptoms']]
|
|
|
|
| 16 |
X = mlb.fit_transform(symptoms)
|
| 17 |
disease = pd.get_dummies(data['Disease'])
|
| 18 |
disease_list = list(disease.columns)
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
# Define the prediction function
|
| 21 |
def predict_disease(symptoms):
|
| 22 |
# Preprocess the user input
|
| 23 |
-
user_symptoms = [symptoms.split(',')]
|
| 24 |
-
user_X = mlb.transform(user_symptoms)
|
| 25 |
|
| 26 |
# Make the prediction
|
| 27 |
prediction = model.predict(np.expand_dims(user_X, axis=2))
|
| 28 |
predicted_disease = disease_list[np.argmax(prediction)]
|
| 29 |
predicted_antibiotics = data.loc[data['Disease'] == predicted_disease, 'Antibiotics'].values[0]
|
| 30 |
|
| 31 |
-
# Return the prediction
|
| 32 |
-
return f"Disease: {predicted_disease}\nAntibiotics: {predicted_antibiotics}"
|
| 33 |
|
| 34 |
# Define the Gradio interface
|
| 35 |
inputs = gr.inputs.Textbox(label="Symptoms")
|
|
@@ -37,4 +43,4 @@ outputs = gr.outputs.Textbox(label="Prediction")
|
|
| 37 |
gradio_interface = gr.Interface(predict_disease, inputs, outputs, title="Disease Prediction App")
|
| 38 |
|
| 39 |
# Launch the Gradio interface
|
| 40 |
-
gradio_interface.launch()
|
|
|
|
| 13 |
# Preprocess the dataset
|
| 14 |
mlb = MultiLabelBinarizer()
|
| 15 |
symptoms = [s.split(',') for s in data['Symptoms']]
|
| 16 |
+
symptoms = [[symptom.strip().replace('_', '').replace(' ', '').lower() for symptom in sublist] for sublist in symptoms]
|
| 17 |
X = mlb.fit_transform(symptoms)
|
| 18 |
disease = pd.get_dummies(data['Disease'])
|
| 19 |
disease_list = list(disease.columns)
|
| 20 |
|
| 21 |
+
# Evaluate the model on the testing set
|
| 22 |
+
X_test = np.expand_dims(X, axis=2)
|
| 23 |
+
Y_test = disease.values
|
| 24 |
+
loss, accuracy = model.evaluate(X_test, Y_test, verbose=0)
|
| 25 |
+
|
| 26 |
# Define the prediction function
|
| 27 |
def predict_disease(symptoms):
|
| 28 |
# Preprocess the user input
|
| 29 |
+
user_symptoms = [symptom.strip().replace('_', '').replace(' ', '').lower() for symptom in symptoms.split(',')]
|
| 30 |
+
user_X = mlb.transform([user_symptoms])
|
| 31 |
|
| 32 |
# Make the prediction
|
| 33 |
prediction = model.predict(np.expand_dims(user_X, axis=2))
|
| 34 |
predicted_disease = disease_list[np.argmax(prediction)]
|
| 35 |
predicted_antibiotics = data.loc[data['Disease'] == predicted_disease, 'Antibiotics'].values[0]
|
| 36 |
|
| 37 |
+
# Return the prediction and accuracy
|
| 38 |
+
return f"Disease: {predicted_disease}\nAntibiotics: {predicted_antibiotics}\n\nModel accuracy on testing set: {accuracy:.3f}"
|
| 39 |
|
| 40 |
# Define the Gradio interface
|
| 41 |
inputs = gr.inputs.Textbox(label="Symptoms")
|
|
|
|
| 43 |
gradio_interface = gr.Interface(predict_disease, inputs, outputs, title="Disease Prediction App")
|
| 44 |
|
| 45 |
# Launch the Gradio interface
|
| 46 |
+
gradio_interface.launch(share=True)
|