Spaces:
Sleeping
Sleeping
zhangxunhui
commited on
Commit
•
4ecc16a
1
Parent(s):
7e18e7c
Upload app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,29 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.
|
2 |
+
|
3 |
+
# %% auto 0
|
4 |
+
__all__ = ['learn', 'categories', 'image', 'label', 'examples', 'iface', 'classify_image']
|
5 |
+
|
6 |
+
# %% app.ipynb 1
|
7 |
+
import gradio as gr
|
8 |
+
from fastai.vision.all import *
|
9 |
+
from fastai.data.all import *
|
10 |
+
|
11 |
+
# %% app.ipynb 2
|
12 |
+
learn = load_learner('model.pkl')
|
13 |
+
|
14 |
+
# %% app.ipynb 3
|
15 |
+
categories = ('Badminton', 'Cricket', 'Karate', 'Soccer', 'Swimming', 'Tennis', 'Wrestling')
|
16 |
+
|
17 |
+
# %% app.ipynb 4
|
18 |
+
def classify_image(img):
|
19 |
+
pred, idx, probs = learn.predict(img)
|
20 |
+
return dict(zip(categories, map(float, probs)))
|
21 |
+
|
22 |
+
# %% app.ipynb 5
|
23 |
+
image = gr.inputs.Image(shape(224, 224))
|
24 |
+
label = gr.outputs.Label()
|
25 |
+
examples = ['Badminton.jpg', 'Cricket.jpg', 'Karate.jpg', 'Soccer.jpg', 'Swimming.jpg', 'Tennis.jpg', 'Wrestling.jpg']
|
26 |
+
|
27 |
+
# %% app.ipynb 6
|
28 |
+
iface = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
29 |
+
iface.launch(inline=False)
|