Spaces:
Sleeping
Sleeping
import gradio as gr | |
import tensorflow as tf | |
from tensorflow.keras.models import load_model | |
import numpy as np | |
from PIL import Image | |
import io | |
def predict_input_image(img): | |
img = img/255 | |
img = tf.image.resize(img, [224, 224]) | |
img = np.expand_dims(img, axis=0) | |
my_model = load_model('chest_model.h5') | |
# Set a threshold for binary classification | |
threshold = 0.7 | |
# Make predictions using your model | |
predictions = my_model.predict(img) | |
# Convert predictions to binary (0 or 1) based on the threshold | |
binary_prediction = 'Pneumonia Detected' if predictions[0][0] > threshold else 'No Pneumonia Detected' | |
# Return the binary prediction | |
return binary_prediction | |
# Define Gradio interface | |
iface = gr.Interface( | |
fn=predict_input_image, | |
inputs=gr.Image(), | |
outputs='text', | |
allow_flagging = 'manual', | |
flagging_dir = 'Elegbede/Pneumonia_Detection/flagged', | |
examples= [ | |
['Pneumonia_01.jpeg'], | |
['Pneumonia_02.jpeg'], | |
['Pneumonia_03.jpeg'], | |
['Normal_01.jpeg'], | |
['Normal_02.jpeg'], | |
['Normal_03.jpeg'] | |
] | |
) | |
# Launch the interface | |
iface.launch() |