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): # 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) my_model = load_model('Brain_Tumor_Model.h5') # Set a threshold for binary classification threshold = 0.5 # Make predictions using your model predictions = my_model.predict(img) # Convert predictions to binary (0 or 1) based on the threshold binary_prediction = 'Tumor Detected' if predictions[0][0] > threshold else 'No Tumor Detected' # Return the binary prediction return binary_prediction # Define Gradio interface iface = gr.Interface( fn=predict_input_image, inputs=gr.Image(), outputs='text', examples = [ ['G_101.jpg'], ['N_10.jpg'], ['M_107.jpg'], ['N_101.jpg'], ['M_119.jpg'], ['N_128.jpg'] ] ) # Launch the interface iface.launch()