Elegbede's picture
Update app.py
fa125a5
raw
history blame
889 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):
# Normalize the image by cropping (center crop)
h, w = img.shape[:2]
crop_start_x = (w - 224) // 2
crop_start_y = (h - 224) // 2
img = img[crop_start_y:crop_start_y+224, crop_start_x:crop_start_x+224]
img = tf.image.resize(img, [224,224])
img = np.expand_dims(img, axis = 0)
# Make predictions
model = tf.keras.models.load_model('Tumor_Model.h5')
prediction = model.predict(img)
result = 'No Tumor Detected' if prediction[0][0] > 0.5 else 'Tumor detected'
return prediction
# Define Gradio interface
iface = gr.Interface(
fn=predict_input_image,
inputs= 'image',
outputs="text",
)
# Launch the interface
iface.launch()