ish028792 commited on
Commit
4dcf01a
·
verified ·
1 Parent(s): cdc4a38

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -15
app.py CHANGED
@@ -3,32 +3,24 @@ import tensorflow as tf
3
  import numpy as np
4
  from PIL import Image
5
 
6
- # Load trained models
7
- diabetes_model = tf.keras.models.load_model("diabetes_model.h5")
8
  pneumonia_model = tf.keras.models.load_model("pneumonia_model.h5")
9
 
10
- def predict_disease(image_path, disease):
11
  img = Image.open(image_path).convert("RGB").resize((128, 128))
12
  img_array = np.array(img) / 255.0
13
  img_array = np.expand_dims(img_array, axis=0)
14
 
15
- if disease == "Diabetes":
16
- model = diabetes_model
17
- elif disease == "Pneumonia":
18
- model = pneumonia_model
19
- else:
20
- return "Invalid disease selected"
21
-
22
- prediction = model.predict(img_array)
23
  return "Positive" if prediction[0][0] > 0.5 else "Negative"
24
 
25
  # Gradio Interface
26
  interface = gr.Interface(
27
- fn=predict_disease,
28
- inputs=[gr.Image(type="filepath"), gr.Radio(["Diabetes", "Pneumonia"])],
29
  outputs="text",
30
- title="Disease Prediction",
31
- description="Upload an image and select a disease to get a prediction."
32
  )
33
 
34
  # Launch app
 
3
  import numpy as np
4
  from PIL import Image
5
 
6
+ # Load trained pneumonia model
 
7
  pneumonia_model = tf.keras.models.load_model("pneumonia_model.h5")
8
 
9
+ def predict_pneumonia(image_path):
10
  img = Image.open(image_path).convert("RGB").resize((128, 128))
11
  img_array = np.array(img) / 255.0
12
  img_array = np.expand_dims(img_array, axis=0)
13
 
14
+ prediction = pneumonia_model.predict(img_array)
 
 
 
 
 
 
 
15
  return "Positive" if prediction[0][0] > 0.5 else "Negative"
16
 
17
  # Gradio Interface
18
  interface = gr.Interface(
19
+ fn=predict_pneumonia,
20
+ inputs=gr.Image(type="filepath"),
21
  outputs="text",
22
+ title="Pneumonia Prediction",
23
+ description="Upload an image to get a pneumonia prediction."
24
  )
25
 
26
  # Launch app