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('Model_catsVSdogs.h5') # Define a function to make predictions def predict_image(img): # Preprocess the image img = img.resize((256,256)) # Resize the image to 224x224 pixels img_array = image.img_to_array(img) # Convert the image to an array img_array = np.expand_dims(img_array, axis=0) # Add a batch dimension img_array = img_array / 255.0 # Normalize the image # Make a prediction prediction = model.predict(img_array) if prediction[0] < 0.5: return "Cat" else: return "Dog" # Create the Gradio interface interface = gr.Interface(fn=predict_image, inputs=gr.Image(type="pil"), outputs="text", title="Cat and Dog Classifier", description="Upload an image of a cat or dog and the model will predict which one it is.") # Launch the interface interface.launch(share=True)