Sirui He commited on
Commit
483a943
1 Parent(s): 891347e

Add application file

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastai.vision.all import *
2
+ import gradio as gr
3
+
4
+ def is_cat(x):
5
+ return x[0].isupper()
6
+
7
+ # Gradio执行一个函数
8
+ def classify_image(img):
9
+ pred, idx, probs = learn.predict(img)
10
+ return dict(zip(categories, map(float,probs))) # 不能处理tensor,转为float
11
+
12
+ learn = load_learner('model/model.pkl')
13
+ categories = ('Dog', 'Cat')
14
+ image = gr.inputs.Image(shape=(192, 192))
15
+ label = gr.outputs.Label()
16
+ examples = ['sample/dog.jpg', 'sample/cat.jpg']
17
+
18
+ # 创建并启动
19
+ intf = gr.Interface(fn=classify_image,
20
+ inputs=image,
21
+ outputs=label,
22
+ examples=examples)
23
+
24
+ intf.launch(inline=False)