import gradio as gr import tensorflow as tf # def greet(name): # return "Hello " + name + "!!" def predict_image(image): # Preprocess the image image = image.reshape((1, 160, 160, 3)) model = tf.keras.models.load_model('./cat_dog_recognition.h5') # Make prediction pred = model.predict(image) predicted_label = f"{(1-pred[0][0])*100}% Dog \n{pred[0][0]*100}% Cat \nFinal Prediction : {'Dog' if pred[0][0] < 0.5 else 'Cat'}" # Return the predicted label return predicted_label # input_image = [gr.components.Image(type="filepath" , label="Input Image"),] # iface = gr.Interface(fn=detect, inputs=input_image, outputs="text" , title="Cat vs Dog Detector") # iface.launch() image_input = gr.inputs.Image(shape=(160,160)) label_output = gr.outputs.Textbox() # Create the Gradio interface gr.Interface(fn=predict_image, inputs=image_input, outputs=label_output).launch()