File size: 525 Bytes
5d6feb4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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()