import gradio as gr import tensorflow as tf import numpy as np from PIL import Image # Load model model = tf.keras.models.load_model("dogcat_model.h5") def predict(image): image = image.convert("RGB").resize((224,224)) image = np.array(image) / 255.0 image = np.expand_dims(image, axis=0) pred = model.predict(image)[0][0] return {"Cat": float(1-pred), "Dog": float(pred)} iface = gr.Interface( fn=predict, inputs=gr.Image(type="pil"), outputs=gr.Label(num_top_classes=2) ) iface.launch()