Spaces:
Sleeping
Sleeping
Commit
·
333c10b
1
Parent(s):
2d61d7e
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import pandas as pd
|
|
| 3 |
import numpy as np
|
| 4 |
from sklearn.preprocessing import MultiLabelBinarizer
|
| 5 |
from keras.models import load_model
|
|
|
|
| 6 |
|
| 7 |
# Load the trained model
|
| 8 |
model = load_model('model.h5')
|
|
@@ -28,20 +29,25 @@ def predict_disease(symptoms):
|
|
| 28 |
user_symptoms = [symptoms.split(',')]
|
| 29 |
user_X = mlb.transform(user_symptoms)
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
# Make the prediction
|
| 32 |
-
|
| 33 |
-
predicted_disease = disease_list[np.argmax(
|
| 34 |
predicted_antibiotics = data.loc[data['Disease'] == predicted_disease, 'Antibiotics'].values[0]
|
| 35 |
|
| 36 |
-
#
|
| 37 |
-
|
|
|
|
|
|
|
| 38 |
|
| 39 |
# Define the Gradio interface
|
| 40 |
inputs = gr.inputs.Textbox(label="Symptoms")
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
gradio_interface = gr.Interface(fn=predict_disease, inputs=inputs, outputs=[disease_output, antibiotics_output, accuracy_output], title="Disease Prediction App")
|
| 45 |
|
| 46 |
-
# Launch the Gradio interface
|
| 47 |
gradio_interface.launch()
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
from sklearn.preprocessing import MultiLabelBinarizer
|
| 5 |
from keras.models import load_model
|
| 6 |
+
import time
|
| 7 |
|
| 8 |
# Load the trained model
|
| 9 |
model = load_model('model.h5')
|
|
|
|
| 29 |
user_symptoms = [symptoms.split(',')]
|
| 30 |
user_X = mlb.transform(user_symptoms)
|
| 31 |
|
| 32 |
+
# Show loading animation
|
| 33 |
+
prediction.update("Loading...")
|
| 34 |
+
time.sleep(1)
|
| 35 |
+
|
| 36 |
# Make the prediction
|
| 37 |
+
prediction_array = model.predict(np.expand_dims(user_X, axis=2))[0]
|
| 38 |
+
predicted_disease = disease_list[np.argmax(prediction_array)]
|
| 39 |
predicted_antibiotics = data.loc[data['Disease'] == predicted_disease, 'Antibiotics'].values[0]
|
| 40 |
|
| 41 |
+
# Display prediction and accuracy
|
| 42 |
+
accuracy_percent = f"{accuracy*100:.2f}%"
|
| 43 |
+
result = f"Disease: {predicted_disease}\nAntibiotics: {predicted_antibiotics}\n\nModel accuracy on testing set: {accuracy_percent}"
|
| 44 |
+
prediction.update(result)
|
| 45 |
|
| 46 |
# Define the Gradio interface
|
| 47 |
inputs = gr.inputs.Textbox(label="Symptoms")
|
| 48 |
+
outputs = gr.outputs.Textbox(label="Prediction")
|
| 49 |
+
prediction = gr.outputs.Textbox("Loading...")
|
| 50 |
+
gradio_interface = gr.Interface(predict_disease, inputs, outputs, title="Disease Prediction App", live=True, outputs=[outputs, prediction])
|
|
|
|
| 51 |
|
| 52 |
+
# Launch the Gradio interface
|
| 53 |
gradio_interface.launch()
|