Spaces:
Sleeping
Sleeping
Mikael Kermorgant
commited on
Commit
·
e77804d
1
Parent(s):
cac9279
add app.py exported code
Browse files
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.
|
2 |
+
|
3 |
+
# %% auto 0
|
4 |
+
__all__ = ['learn', 'categories', 'image', 'label', 'examples', 'intf', 'is_cat', 'classify_image']
|
5 |
+
|
6 |
+
# %% app.ipynb 1
|
7 |
+
from fastai.vision.all import *
|
8 |
+
import gradio as gr
|
9 |
+
import PIL
|
10 |
+
|
11 |
+
def is_cat(x): return x[0].isupper()
|
12 |
+
|
13 |
+
# %% app.ipynb 3
|
14 |
+
learn = load_learner('model.pkl')
|
15 |
+
|
16 |
+
# %% app.ipynb 5
|
17 |
+
categories = ('Dog', 'Cat')
|
18 |
+
|
19 |
+
def classify_image(img):
|
20 |
+
pred, idx, probs = learn.predict(img)
|
21 |
+
return dict(zip(categories, map(float, probs)))
|
22 |
+
|
23 |
+
# %% app.ipynb 7
|
24 |
+
image = gr.inputs.Image(shape=(192,192))
|
25 |
+
label = gr.outputs.Label()
|
26 |
+
examples = ["dog1.jpg", "Cat.jpg", "Cat2.jpg"]
|
27 |
+
|
28 |
+
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
29 |
+
intf.launch(inline=False)
|