Update app.py
Browse files
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
|
| 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
|
| 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 |
-
|
| 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=
|
| 28 |
-
inputs=
|
| 29 |
outputs="text",
|
| 30 |
-
title="
|
| 31 |
-
description="Upload an image
|
| 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
|