Elegbede's picture
Update app.py
1b96c12
raw
history blame
810 Bytes
import gradio as gr
import tensorflow as tf
from tensorflow.keras.models import load_model
import numpy as np
from tensorflow.keras.preprocessing import image
def predict_input_image(img_path):
img = Image.open(img_path)
img = img.resize((224, 224,3))
img_array = image.img_to_array(img)
img_array = np.expand_dims(img_array, axis=0) # Reshape the image to match the model input
# Make predictions
model = tf.keras.models.load_model('Tumor_Model.h5')
prediction = model.predict(img_array)
result = 'No Tumor Detected' if prediction[0][0] > 0.5 else 'Tumor detected'
return f"Prediction: {result}"
# Define Gradio interface
iface = gr.Interface(
fn=predict_input_image,
inputs=gr.Image(type = 'pil'),
outputs="text",
)
# Launch the interface
iface.launch()