Spaces:
Runtime error
Runtime error
Commit
·
0340ddc
1
Parent(s):
61753be
Add application file
Browse files
app.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# AUTOGENERATED! DO NOT EDIT! File to edit: chickli.ipynb.
|
2 |
+
|
3 |
+
# %% auto 0
|
4 |
+
__all__ = ['temp', 'learn', 'breeds', 'image', 'label', 'examples', 'intf', 'classify_image']
|
5 |
+
|
6 |
+
# %% chickli.ipynb 2
|
7 |
+
#!pip install fastbook
|
8 |
+
import fastbook
|
9 |
+
from fastbook import *
|
10 |
+
#!pip install fastai
|
11 |
+
from fastai.vision.widgets import *
|
12 |
+
#!pip install gradio
|
13 |
+
import gradio as gr
|
14 |
+
|
15 |
+
import IPython
|
16 |
+
from IPython.display import display
|
17 |
+
from PIL import Image
|
18 |
+
|
19 |
+
def search_images(term, max_images=50):
|
20 |
+
print(f"Searching for '{term}'")
|
21 |
+
return search_images_ddg(term, max_images)
|
22 |
+
|
23 |
+
# %% chickli.ipynb 3
|
24 |
+
import pathlib
|
25 |
+
temp = pathlib.PosixPath
|
26 |
+
pathlib.PosixPath = pathlib.WindowsPath
|
27 |
+
#plt = platform.system()
|
28 |
+
#if plt == 'Linux': pathlib.WindowsPath = pathlib.PosixPath
|
29 |
+
|
30 |
+
learn = load_learner('model.pkl')
|
31 |
+
|
32 |
+
breeds = ('Labrador Retrievers','German Shepherds','Golden Retrievers','French Bulldogs','Bulldogs','Beagles','Poodles','Rottweilers','Chihuahua')
|
33 |
+
|
34 |
+
def classify_image(img):
|
35 |
+
pred,idx,probs = learn.predict(img)
|
36 |
+
#return dict(zip(breeds, map(float,probs)))
|
37 |
+
return "This is " + pred
|
38 |
+
|
39 |
+
image = gr.components.Image()
|
40 |
+
label = gr.components.Label()
|
41 |
+
|
42 |
+
examples = ['dog.jpg','labrador.jpeg','dunno.jpg']
|
43 |
+
|
44 |
+
for x in examples:
|
45 |
+
Image.open(x)
|
46 |
+
|
47 |
+
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
48 |
+
intf.launch(inline=False,share=True)
|