File size: 648 Bytes
9ae8b29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import torch
from utils import process_image, load_saved_model
import gradio as gr

MODEL_PATH = "model.pt"
CATEGORIES = ("Dog", "Cat")
model = load_saved_model(MODEL_PATH)

def predict_pet(image):
    with torch.no_grad():
        model.eval()
        x = process_image(image)
        probs = model(x).squeeze().tolist()

    return dict(zip(CATEGORIES, probs))

demo = gr.Interface(fn=predict_pet, inputs=gr.Image(label="Image"), outputs=gr.Label(label="Type of Pet"), allow_flagging="never",
                    title="Cat or Dog ?", examples="examples", description="This is a small image classification model for cats and dogs")
demo.launch()