Upload app.py
Browse files
app.py
CHANGED
@@ -4,20 +4,31 @@
|
|
4 |
Automatically generated by Colaboratory.
|
5 |
|
6 |
Original file is located at
|
7 |
-
https://colab.research.google.com/drive/
|
8 |
"""
|
9 |
|
|
|
10 |
|
11 |
-
|
12 |
from fastai.vision.all import *
|
13 |
import gradio as gr
|
14 |
|
|
|
|
|
|
|
15 |
learn = load_learner('model.pkl')
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
-
gr.Interface(fn=
|
|
|
|
4 |
Automatically generated by Colaboratory.
|
5 |
|
6 |
Original file is located at
|
7 |
+
https://colab.research.google.com/drive/1sm_pZkdxzPTsmU4kQ9Sdiq5VlFEqRWDQ
|
8 |
"""
|
9 |
|
10 |
+
__all__ = ['is_cat', 'learn', 'classify_image', 'categories', 'image', 'label', 'examples', 'intf']
|
11 |
|
12 |
+
# Cell
|
13 |
from fastai.vision.all import *
|
14 |
import gradio as gr
|
15 |
|
16 |
+
def is_cat(x): return x[0].isupper()
|
17 |
+
|
18 |
+
# Cell
|
19 |
learn = load_learner('model.pkl')
|
20 |
|
21 |
+
# Cell
|
22 |
+
categories = ('Dog', 'Cat')
|
23 |
+
|
24 |
+
def classify_image(img):
|
25 |
+
pred,idx,probs = learn.predict(img)
|
26 |
+
return dict(zip(categories, map(float,probs)))
|
27 |
+
|
28 |
+
# Cell
|
29 |
+
image = gr.inputs.Image(shape=(192, 192))
|
30 |
+
label = gr.outputs.Label()
|
31 |
+
examples = ['dog.jpg', 'cat.jpg', 'dunno.jpg']
|
32 |
|
33 |
+
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
34 |
+
intf.launch(inline=False)
|