Putting the app file at the root
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# AUTOGENERATED! DO NOT EDIT! File to edit: ../app.ipynb.
|
2 |
+
|
3 |
+
# %% auto 0
|
4 |
+
__all__ = ['im', 'temp', 'learn', 'categories', 'image', 'label', 'examples', 'intf', 'classify_image']
|
5 |
+
|
6 |
+
# %% ../app.ipynb 2
|
7 |
+
im = PILImage.create('dog.jpeg')
|
8 |
+
im.thumbnail((192,192))
|
9 |
+
im
|
10 |
+
|
11 |
+
# %% ../app.ipynb 3
|
12 |
+
import pathlib
|
13 |
+
temp = pathlib.PosixPath
|
14 |
+
pathlib.PosixPath = pathlib.WindowsPath
|
15 |
+
|
16 |
+
learn = load_learner('model.pkl')
|
17 |
+
|
18 |
+
# %% ../app.ipynb 5
|
19 |
+
categories = ('Dog', 'Cat')
|
20 |
+
|
21 |
+
def classify_image(img):
|
22 |
+
pred,idx,probs = learn.predict(img)
|
23 |
+
return dict(zip(categories, map(float,probs)))
|
24 |
+
|
25 |
+
# %% ../app.ipynb 7
|
26 |
+
image = gr.Image(height=192,width=192)
|
27 |
+
label = gr.Label()
|
28 |
+
examples = ['dog.jpeg', 'cat.jpeg', 'dunno.jpeg']
|
29 |
+
|
30 |
+
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
31 |
+
intf.launch(inline=False,share=True)
|