Toqi Tahamid
commited on
Commit
•
7fd0d00
1
Parent(s):
2c44690
update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
|
|
|
1 |
+
# AUTOGENERATED! DO NOT EDIT! File to edit: ../Deploy to HF Space.ipynb.
|
2 |
+
|
3 |
+
# %% auto 0
|
4 |
+
__all__ = ['learn', 'bear_types', 'image', 'label', 'examples', 'intf', 'classify_image']
|
5 |
+
|
6 |
+
# %% ../Deploy to HF Space.ipynb 1
|
7 |
+
from fastai.vision.all import *
|
8 |
import gradio as gr
|
9 |
|
10 |
+
# %% ../Deploy to HF Space.ipynb 3
|
11 |
+
learn = load_learner('model.pkl')
|
12 |
+
|
13 |
+
# %% ../Deploy to HF Space.ipynb 7
|
14 |
+
bear_types = ('grizzly', 'black', 'teddy')
|
15 |
+
bear_types = sorted(bear_types)
|
16 |
+
|
17 |
+
# bear_types
|
18 |
+
|
19 |
+
# %% ../Deploy to HF Space.ipynb 9
|
20 |
+
def classify_image(img):
|
21 |
+
pred, idx, probs = learn.predict(img)
|
22 |
+
return dict(zip(bear_types, map(float, probs)))
|
23 |
+
|
24 |
+
# %% ../Deploy to HF Space.ipynb 12
|
25 |
+
image = gr.inputs.Image(shape=(224, 224))
|
26 |
+
label = gr.outputs.Label()
|
27 |
+
examples = ['black-bear.jpg', 'grizzly-bear.jpg', 'teddy-bear.jpg']
|
28 |
|
29 |
+
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
30 |
+
intf.launch(inline=False)
|