rizmyabdulla commited on
Commit
13c1f49
·
1 Parent(s): 333c10b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -14
app.py CHANGED
@@ -3,7 +3,6 @@ import pandas as pd
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,25 +28,18 @@ def predict_disease(symptoms):
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()
 
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
  user_symptoms = [symptoms.split(',')]
29
  user_X = mlb.transform(user_symptoms)
30
 
 
 
 
 
31
  # Make the prediction
32
+ prediction = model.predict(np.expand_dims(user_X, axis=2))
33
+ predicted_disease = disease_list[np.argmax(prediction)]
34
  predicted_antibiotics = data.loc[data['Disease'] == predicted_disease, 'Antibiotics'].values[0]
35
 
36
+ # Return the prediction and accuracy
37
+ return f"Disease: {predicted_disease}\nAntibiotics: {predicted_antibiotics}", f"Model accuracy on testing set: {accuracy:.3f}"
 
 
38
 
39
  # Define the Gradio interface
40
  inputs = gr.inputs.Textbox(label="Symptoms")
41
+ outputs = [gr.outputs.Textbox(label="Prediction"), gr.outputs.Textbox(label="Accuracy")]
42
+ gradio_interface = gr.Interface(predict_disease, inputs, outputs, title="Disease Prediction App")
 
43
 
44
  # Launch the Gradio interface
45
  gradio_interface.launch()