Team Ai
Apppublic

gnarlynerd/tutorial2

sourceHugging Faceapache-2.0updated 4y agoView on Hugging Face
0likes
demo.py71 linesDownload Raw Back to root
1#!/usr/bin/env python2# coding: utf-83 4# In[8]:5 6 7 8 9 10# In[ ]:11 12 13#|export14from fastai.vision.all import *15import gradio as gr16 17def is_cat(x): return x[0].isupper()18 19 20# In[10]:21 22 23 24 25 26# In[11]:27 28 29#|export30learn = load_learner('model.pkl')31 32 33# In[12]:34 35 36 37 38 39# In[13]:40 41 42#|export43categories = ('Dog', 'Cat')44 45def classify_image(img):46    pred,idx,probs = learn.predict(img)47    return dict(zip(categories, map(float,probs)))48 49 50# In[14]:51 52 53 54 55 56# In[15]:57 58 59#|export60image = gr.inputs.Image(shape=(192, 192))61label = gr.outputs.Label()62examples = ['dog.jpg', 'cat.jpg', 'dunno.jpg']63 64intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)65intf.launch(inline=False)66 67 68 69 70 71