import gradio as gr import tensorflow as tf from tensorflow.keras.preprocessing import image import numpy as np # Load the trained model model = tf.keras.models.load_model('cat_dog_classifier_vgg16.h5') # Define a function to make predictions def predict_image(img): # Preprocess the image img = img.resize((224, 224)) img_array = image.img_to_array(img) img_array = np.expand_dims(img_array, axis=0) img_array = img_array / 255.0 # Make a prediction prediction = model.predict(img_array) if prediction[0] < 0.5: return "Cat" else: return "Dog" # Create the Gradio interface iface = gr.Interface( fn=predict_image, inputs=gr.inputs.Image(type="pil"), outputs="text", title="Cat and Dog Classifier", description="Upload an image of a cat or a dog and the model will classify it.", examples=["cat_example.jpg", "dog_example.jpg"] ) # Launch the interface iface.launch()