Spaces:
Runtime error
Runtime error
Commit
·
2e0ff5d
1
Parent(s):
70f0956
updated dog vs cat classifier
Browse files- app.py +29 -4
- app_old.py +7 -0
app.py
CHANGED
|
@@ -1,7 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
def
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
| 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_img']
|
| 5 |
+
|
| 6 |
+
# %% app.ipynb 4
|
| 7 |
+
from fastai.vision.all import *
|
| 8 |
+
from fastbook import search_images_ddg, download_url
|
| 9 |
import gradio as gr
|
| 10 |
|
| 11 |
+
def is_cat(x): return x[0].isupper()
|
| 12 |
+
|
| 13 |
+
# %% app.ipynb 8
|
| 14 |
+
learn = load_learner('model.pkl')
|
| 15 |
+
|
| 16 |
+
# %% app.ipynb 9
|
| 17 |
+
learn.predict(im)
|
| 18 |
+
|
| 19 |
+
# %% app.ipynb 10
|
| 20 |
+
categories = ('Dog', 'Cat')
|
| 21 |
+
|
| 22 |
+
def classify_img(img):
|
| 23 |
+
pred, idx, probs = learn.predict(img)
|
| 24 |
+
return dict(zip(categories, map(float, probs)))
|
| 25 |
+
|
| 26 |
+
# %% app.ipynb 12
|
| 27 |
+
image = gr.inputs.Image(shape=(192, 192))
|
| 28 |
+
label = gr.outputs.Label()
|
| 29 |
+
examples = ['images/dog.jpg', 'images/cat.jpg', 'images/catdog.jpg']
|
| 30 |
|
| 31 |
+
intf = gr.Interface(fn=classify_img, inputs=image, outputs=label, examples=examples)
|
| 32 |
+
intf.launch(inline=False)
|
app_old.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
def greet(name):
|
| 4 |
+
return "Hello " + name + "!!"
|
| 5 |
+
|
| 6 |
+
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
| 7 |
+
iface.launch()
|