Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
from fastai.vision.all import *
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def is_cat(x): return x[0].isupper()
|
| 7 |
+
|
| 8 |
+
learn = load_learner("model.pkl")
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
im = PILImage.create('dog.jpg')
|
| 12 |
+
im.thumbnail((192,192))
|
| 13 |
+
im
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
learn.predict(im)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
categories = ("dog","cat")
|
| 21 |
+
def classify_image(img):
|
| 22 |
+
pred,idx,probs=learn.predict(img)
|
| 23 |
+
return dict(zip(categories,map(float,probs)))
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
classify_image(im)
|
| 27 |
+
|
| 28 |
+
image = gr.inputs.Image(shape=(192,192))
|
| 29 |
+
label= gr.outputs.Label()
|
| 30 |
+
examples = ['dog.jpg','cat.jpg','example.jpg']
|
| 31 |
+
|
| 32 |
+
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples = examples)
|
| 33 |
+
intf.launch(inline=False)
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
|