Add application file
Browse files- testing/app.py +29 -0
testing/app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# AUTOGENERATED! DO NOT EDIT! File to edit: ../app.ipynb.
|
2 |
+
|
3 |
+
# %% auto 0
|
4 |
+
__all__ = ['learner', 'categories', 'image', 'label', 'examples', 'intf', 'is_cat', 'classify_image']
|
5 |
+
|
6 |
+
# %% ../app.ipynb 1
|
7 |
+
from fastai.vision.all import *
|
8 |
+
from huggingface_hub import push_to_hub_fastai, from_pretrained_fastai
|
9 |
+
import gradio as gr
|
10 |
+
|
11 |
+
def is_cat(x): return x[0].isupper()
|
12 |
+
|
13 |
+
# %% ../app.ipynb 4
|
14 |
+
learner = load_learner('model.pkl')
|
15 |
+
|
16 |
+
# %% ../app.ipynb 6
|
17 |
+
categories = ('Dog', 'Cat')
|
18 |
+
|
19 |
+
def classify_image(img):
|
20 |
+
pred, idx, probs = learner.predict(img)
|
21 |
+
return dict(zip(categories, map(float, probs)))
|
22 |
+
|
23 |
+
# %% ../app.ipynb 8
|
24 |
+
image = gr.inputs.Image(shape=(192,192))
|
25 |
+
label = gr.outputs.Label()
|
26 |
+
examples = ['dog.jpg','cat.jpg', 'doat.jpg', 'gaumeo.jpg']
|
27 |
+
|
28 |
+
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
29 |
+
intf.launch(inline=False)
|