Update app.py
Browse files
app.py
CHANGED
|
@@ -2,17 +2,20 @@ import os
|
|
| 2 |
|
| 3 |
os.system("pip install fastai gradio torch")
|
| 4 |
|
| 5 |
-
__all__ = ['is_cat', 'learn', 'classify_image', 'image', 'label', 'examples', '
|
| 6 |
|
|
|
|
| 7 |
from fastai.vision.all import *
|
| 8 |
import gradio as gr
|
| 9 |
import pathlib
|
| 10 |
|
| 11 |
def is_cat(x): return x[0].isupper()
|
| 12 |
|
|
|
|
| 13 |
learn = load_learner('model.pkl')
|
| 14 |
|
| 15 |
-
|
|
|
|
| 16 |
|
| 17 |
def classify_image(img):
|
| 18 |
img = PILImage.create(img)
|
|
@@ -23,5 +26,5 @@ image = gr.Image(type="pil")
|
|
| 23 |
label = gr.Label()
|
| 24 |
examples = ['dog.jpg', 'cat.jpg', 'dunno.jpg']
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
|
|
|
| 2 |
|
| 3 |
os.system("pip install fastai gradio torch")
|
| 4 |
|
| 5 |
+
__all__ = ['is_cat', 'learn', 'classify_image', 'image', 'label', 'examples', 'intf']
|
| 6 |
|
| 7 |
+
#导包
|
| 8 |
from fastai.vision.all import *
|
| 9 |
import gradio as gr
|
| 10 |
import pathlib
|
| 11 |
|
| 12 |
def is_cat(x): return x[0].isupper()
|
| 13 |
|
| 14 |
+
#从模型中获取数据
|
| 15 |
learn = load_learner('model.pkl')
|
| 16 |
|
| 17 |
+
#当前的分类
|
| 18 |
+
categories = ('Dog', 'Cat','Rabbit')
|
| 19 |
|
| 20 |
def classify_image(img):
|
| 21 |
img = PILImage.create(img)
|
|
|
|
| 26 |
label = gr.Label()
|
| 27 |
examples = ['dog.jpg', 'cat.jpg', 'dunno.jpg']
|
| 28 |
|
| 29 |
+
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
| 30 |
+
intf.launch()
|