Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,28 +1,28 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import numpy as np
|
| 3 |
-
from tensorflow.keras.models import load_model
|
| 4 |
-
from tensorflow.keras.preprocessing import image
|
| 5 |
-
|
| 6 |
-
# Load your saved model (.keras file)
|
| 7 |
-
model = load_model("malaria_model.keras")
|
| 8 |
-
|
| 9 |
-
IMG_SIZE = (64, 64) # matches your training
|
| 10 |
-
|
| 11 |
-
def predict(img):
|
| 12 |
-
img = img.convert("RGB")
|
| 13 |
-
img = img.resize(IMG_SIZE)
|
| 14 |
-
img_array = image.img_to_array(img)
|
| 15 |
-
img_array = np.expand_dims(img_array, axis=0)
|
| 16 |
-
img_array = img_array / 255.0 # normalization
|
| 17 |
-
|
| 18 |
-
prediction = model.predict(img_array)[0][0]
|
| 19 |
-
label = "Infected" if prediction > 0.5 else "Uninfected"
|
| 20 |
-
return label
|
| 21 |
-
|
| 22 |
-
gr.Interface(
|
| 23 |
-
fn=predict,
|
| 24 |
-
inputs=gr.Image(type="pil"),
|
| 25 |
-
outputs=gr.Textbox(label="Prediction"),
|
| 26 |
-
title="Malaria Cell Image Predictor",
|
| 27 |
-
description="Upload a blood smear cell image to detect malaria (Infected/Uninfected)."
|
| 28 |
-
).launch()
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import numpy as np
|
| 3 |
+
from tensorflow.keras.models import load_model
|
| 4 |
+
from tensorflow.keras.preprocessing import image
|
| 5 |
+
|
| 6 |
+
# Load your saved model (.keras file)
|
| 7 |
+
model = load_model("malaria_model.keras")
|
| 8 |
+
|
| 9 |
+
IMG_SIZE = (64, 64) # matches your training
|
| 10 |
+
|
| 11 |
+
def predict(img):
|
| 12 |
+
img = img.convert("RGB")
|
| 13 |
+
img = img.resize(IMG_SIZE)
|
| 14 |
+
img_array = image.img_to_array(img)
|
| 15 |
+
img_array = np.expand_dims(img_array, axis=0)
|
| 16 |
+
img_array = img_array / 255.0 # normalization
|
| 17 |
+
|
| 18 |
+
prediction = model.predict(img_array)[0][0]
|
| 19 |
+
label = "Infected" if prediction > 0.5 else "Uninfected"
|
| 20 |
+
return label
|
| 21 |
+
|
| 22 |
+
gr.Interface(
|
| 23 |
+
fn=predict,
|
| 24 |
+
inputs=gr.Image(type="pil"),
|
| 25 |
+
outputs=gr.Textbox(label="Prediction"),
|
| 26 |
+
title="Malaria Cell Image Predictor",
|
| 27 |
+
description="Upload a blood smear cell image to detect malaria (Infected/Uninfected)."
|
| 28 |
+
).launch(share=True)
|