Spaces:
Sleeping
Sleeping
export with nbdev
Browse files
app.py
CHANGED
|
@@ -1,7 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
def greet(name):
|
| 4 |
-
return "Hello " + name + "!!"
|
| 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_image']
|
| 5 |
+
|
| 6 |
+
# %% app.ipynb 2
|
| 7 |
+
from fastai.vision.all import *
|
| 8 |
+
import PIL
|
| 9 |
+
import pathlib
|
| 10 |
import gradio as gr
|
| 11 |
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
def is_cat(x): return x[0].isupper()
|
| 14 |
+
|
| 15 |
+
# %% app.ipynb 4
|
| 16 |
+
# Check if you are on a Windows system
|
| 17 |
+
if sys.platform == 'win32':
|
| 18 |
+
# Set the base PosixPath to WindowsPath
|
| 19 |
+
pathlib.PosixPath = pathlib.WindowsPath
|
| 20 |
+
pathlib.PosixPath
|
| 21 |
+
|
| 22 |
+
# %% app.ipynb 5
|
| 23 |
+
learn =load_learner('cat_dog_model.pkl')
|
| 24 |
+
|
| 25 |
+
# %% app.ipynb 7
|
| 26 |
+
categories= ('Dog', 'Cat')
|
| 27 |
+
|
| 28 |
+
def classify_image(img):
|
| 29 |
+
pred,idx, probs = learn.predict(img)
|
| 30 |
+
return dict(zip(categories, map(float,probs)))
|
| 31 |
+
|
| 32 |
+
# %% app.ipynb 9
|
| 33 |
+
image = gr.Image(height=192,width=192)
|
| 34 |
+
label = gr.Label()
|
| 35 |
+
examples =['dog.jpg', 'cats.jpeg', 'dogs.png']
|
| 36 |
+
|
| 37 |
+
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
| 38 |
+
intf.launch(inline=False)
|