AILearning / app.py
Vincent Jiao
Upload cat or dog model
2644aef
raw
history blame contribute delete
657 Bytes
import gradio as gr
from fastai.vision.all import *
# Define the labeling function used during training
# This must match the function used when the model was trained
def is_cat(x):
return x[0].isupper()
learn = load_learner('cat_or_dog_model.pkl')
categories = ('Dog', 'Cat')
def classify_image(img):
pred, idx, probs = learn.predict(img)
return dict(zip(categories, map(float, probs)))
# Modern Gradio API
intf = gr.Interface(
fn=classify_image,
inputs=gr.Image(),
outputs=gr.Label(num_top_classes=2),
title="Cat or Dog Classifier",
description="Upload an image to classify whether it's a cat or dog"
)
intf.launch()