John Yan
commited on
Commit
·
14ec91d
1
Parent(s):
922fab8
add back
Browse files
app.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from fastai.vision.all import *
|
| 3 |
+
|
| 4 |
+
# def greet(name):
|
| 5 |
+
# return "Hello " + name + "!!" + "and hello world 123f"
|
| 6 |
+
|
| 7 |
+
# iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
| 8 |
+
# iface.launch()
|
| 9 |
+
|
| 10 |
+
def is_cat(x): return x[0].isupper()
|
| 11 |
+
learn = load_learner('model.pkl')
|
| 12 |
+
categories = ('Dog', 'Cat')
|
| 13 |
+
|
| 14 |
+
def classify_image(img):
|
| 15 |
+
pred,idx,probs = learn.predict(img)
|
| 16 |
+
return dict(zip(categories, map(float,probs)))
|
| 17 |
+
|
| 18 |
+
image = gr.inputs.Image(shape=(192,192))
|
| 19 |
+
label = gr.outputs.Label()
|
| 20 |
+
examples = ['dog.png', 'cat.png', 'dunno.png']
|
| 21 |
+
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
| 22 |
+
intf.launch()
|