Spaces:
Runtime error
Runtime error
Viet
commited on
Commit
•
06a3123
1
Parent(s):
39c438f
add application file v1
Browse files
app.py
CHANGED
@@ -1,7 +1,31 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from fastai.vision.all import *
|
3 |
|
4 |
+
#fix some issues with Poxixpath
|
5 |
+
import pathlib
|
6 |
+
temp = pathlib.PosixPath
|
7 |
+
pathlib.PosixPath = pathlib.WindowsPath
|
8 |
|
9 |
+
|
10 |
+
def is_cat(x): return x[0].isupper()
|
11 |
+
|
12 |
+
learn = load_learner('model.pkl')
|
13 |
+
|
14 |
+
# labels = learn.dls.vocab
|
15 |
+
|
16 |
+
# learn.predict(im)
|
17 |
+
|
18 |
+
# %time learn.predict(im)
|
19 |
+
|
20 |
+
categories = ('Dog', 'Cat')
|
21 |
+
|
22 |
+
def classify_image(img):
|
23 |
+
pred,idx,probs = learn.predict(img)
|
24 |
+
return dict(zip(categories, map(float,probs)))
|
25 |
+
|
26 |
+
image = gr.inputs.Image(shape=(192, 192))
|
27 |
+
label = gr.outputs.Label()
|
28 |
+
examples = ['dog.jpg', 'cat.jpg']
|
29 |
+
|
30 |
+
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
31 |
+
intf.launch(inline=False)
|