Add file applications
Browse files- app.py +29 -0
- cat.jpg +0 -0
- doat.jpg +0 -0
- dog.jpg +0 -0
- gaumeo.jpg +0 -0
- requirements.txt +3 -0
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)
|
cat.jpg
ADDED
|
doat.jpg
ADDED
|
dog.jpg
ADDED
|
gaumeo.jpg
ADDED
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastai
|
| 2 |
+
git+https://github.com/huggingface/huggingface_hub
|
| 3 |
+
gradio
|