Elegbede's picture
Update app.py
cf359f7
raw
history blame
814 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
model = tf.keras.models.load_model('tumor_model.h5')
def predict_input_image(img):
# Convert NumPy array to PIL.Image
img = Image.fromarray(np.uint8(img))
img = img.convert('RGB')
img = img.resize((224, 224))
img = np.array(img).reshape(1, 224, 224, 3) # Reshape the image to match the model input
# Make predictions
prediction = model.predict(img)
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="image",
outputs="text",
)
# Launch the interface
iface.launch()