Spaces:
Sleeping
Sleeping
File size: 564 Bytes
c751f41 251a7c9 c751f41 3f3d3ac 4a51d89 14b29a2 251a7c9 bafe32a 251a7c9 bafe32a 251a7c9 4a51d89 bafe32a 01b8134 4a51d89 251a7c9 01b8134 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
import gradio as gr
from fastai.vision.all import *
def is_cat(x): return x[0].isupper()
learner = load_learner("model.pkl")
categories = ("Dog", "Cat")
def classify_image(img):
if img is None:
return {}
img = PILImage.create(img)
pred, pred_idx, probs = learner.predict(img)
return dict(zip(categories, map(float, probs)))
demo = gr.Interface(
fn=classify_image,
inputs=gr.Image(type="pil"),
outputs=gr.Label(),
examples=["cat1.jpeg", "dog1.jpeg", "cat2.jpeg", "dog2.jpg"],
cache_examples=False,
)
demo.launch()
|