File size: 727 Bytes
69e420c
640c560
69e420c
 
c7eed12
69e420c
c7eed12
69e420c
24edf0f
69e420c
a8b751b
5255d86
2cded81
c7eed12
f439787
640c560
c7eed12
 
640c560
 
69e420c
 
 
 
 
 
 
24edf0f
c7eed12
 
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
26
27
28
29
30
import os

os.system("pip install fastai gradio torch")

__all__ = ['is_cat', 'learn', 'classify_image', 'image', 'label', 'examples', 'intf']

#导包
from fastai.vision.all import *
import gradio as gr
import pathlib

def is_cat(x): return x[1].isupper()

#从模型中获取数据
learn = load_learner('model.pkl')

#当前的分类
categories = ('Dog', 'Cat','Rabbit')

def classify_image(img):
    img = PILImage.create(img) 
    pred, idx, probs = learn.predict(img)
    return dict(zip(categories, map(float, probs)))
    
image = gr.Image(type="pil") 
label = gr.Label()
examples = ['dog.jpg', 'cat.jpg', 'dunno.jpg']

intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
intf.launch()