Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,52 +1,26 @@
|
|
1 |
# AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.
|
2 |
|
3 |
# %% auto 0
|
4 |
-
__all__ = ['
|
5 |
-
'is_cat', 'classify_img']
|
6 |
|
7 |
# %% app.ipynb 2
|
8 |
from fastai.vision.all import *
|
9 |
import gradio as gr
|
10 |
-
from fastbook import *
|
11 |
-
from fastai.vision.widgets import *
|
12 |
-
import gradio as gr
|
13 |
-
btn_upload = widgets.FileUpload()
|
14 |
-
out_pl = widgets.Output()
|
15 |
-
lbl_pred = widgets.Label()
|
16 |
-
|
17 |
-
# %% app.ipynb 3
|
18 |
-
# def on_data_change(change):
|
19 |
-
# lbl_pred.value = ''
|
20 |
-
# img = PILImage.create(btn_upload.data[-1])
|
21 |
-
# out_pl.clear_output()
|
22 |
-
# with out_pl: display(img.to_thumb(128,128))
|
23 |
-
# pred,pred_idx,probs = learn_inf.predict(img)
|
24 |
-
# lbl_pred.value = f'Prediction: {pred}; Probability: {probs[pred_idx]:.04f}'
|
25 |
-
|
26 |
-
class DataLoaders(GetAttr):
|
27 |
-
def __init__(self, *loaders): self.loaders = loaders
|
28 |
-
def __getitem__(self, i): return self.loaders[i]
|
29 |
-
train,valid = add_props(lambda i,self: self[i])
|
30 |
-
|
31 |
-
def is_cat(x): return x[0].isupper()
|
32 |
-
|
33 |
-
|
34 |
|
35 |
# %% app.ipynb 4
|
36 |
learn = load_learner('export.pkl')
|
37 |
-
print(type(learn))
|
38 |
|
39 |
-
# %% app.ipynb 7
|
40 |
-
categories = ('black', 'grizzly', 'teddy')
|
41 |
|
42 |
# %% app.ipynb 8
|
43 |
-
def
|
44 |
-
|
45 |
-
return dict(zip(
|
46 |
|
47 |
# %% app.ipynb 10
|
48 |
-
image = gr.
|
49 |
-
label = gr.
|
50 |
-
examples = ['teddy.png', 'grizzly.jpg','black.jpeg']
|
51 |
-
|
52 |
-
intf.
|
|
|
|
1 |
# AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.
|
2 |
|
3 |
# %% auto 0
|
4 |
+
__all__ = ['learn', 'image', 'label', 'examples', 'intf', 'classify_image']
|
|
|
5 |
|
6 |
# %% app.ipynb 2
|
7 |
from fastai.vision.all import *
|
8 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
# %% app.ipynb 4
|
11 |
learn = load_learner('export.pkl')
|
12 |
+
# print(type(learn))
|
13 |
|
|
|
|
|
14 |
|
15 |
# %% app.ipynb 8
|
16 |
+
def classify_image(img):
|
17 |
+
pred,pred_idx,probs = learn.predict(img)
|
18 |
+
return dict(zip(learn.dls.vocab, map(float, probs)))
|
19 |
|
20 |
# %% app.ipynb 10
|
21 |
+
image = gr.components.Image(shape=(192,192))
|
22 |
+
label = gr.components.Label()
|
23 |
+
examples = ['teddy.png', 'grizzly.jpg', 'black.jpeg']
|
24 |
+
|
25 |
+
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
26 |
+
intf.launch(inline=False)
|