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_image(input_image, threshold=0.5): # Load and preprocess the input image img = image.load_img(input_image, target_size=(224, 224)) img = image.img_to_array(img) img = np.expand_dims(img, axis=0) img = img / 255.0 # Normalize the pixel values (if the model expects it) # Make a prediction # Load the saved model loaded_model = load_model('tumor_model.h5') predictions = loaded_model.predict(img) # Assuming it's a binary classification model predicted_probability = predictions[0][0] # Determine the class based on the threshold if predicted_probability > threshold: class_name = 'tumor' else: class_name = 'no tumor' return f'Predicted Class: {class_name}' iface = gr.Interface(fn=predict_image, inputs="image", outputs="text", live=True) iface.launch(share=True)