import gradio as gr import tensorflow as tf from PIL import Image import numpy as np # Load the pre-trained model model = tf.keras.models.load_model('model.h5') # Replace with the path to your saved model # Define a Gradio interface for image classification def classify_image(image): # Preprocess the input image image = Image.fromarray(image) image = image.resize((128, 128)) image = np.array(image) image = image / 255.0 # Normalize the pixel values # Make a prediction prediction = model.predict(np.expand_dims(image, axis=0)) # Get the class label class_label = "Dog" if prediction[0][0] < 0.5 else "Cat" return class_label # Create a Gradio interface iface = gr.Interface(fn=classify_image, inputs="image", outputs="text", capture_session=True) # Launch the Gradio interface iface.launch(server_name="0.0.0.0", server_port=7860)