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): # 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('my_model.h5') predictions = loaded_model.predict(img) # Assuming it's a binary classification model, you can interpret the prediction class_names = ['yes', 'no'] class_index = int(round(predictions[0][0])) class_name = class_names[class_index] return f'Predicted Class: {class_name}' iface = gr.Interface(fn=predict_image, inputs="image", outputs="text") iface.launch(share=True)