Valentina Sanchez
commited on
Commit
·
2f59b4e
1
Parent(s):
92e2484
Add Gradio interface and model loading code
Browse files
app.py
CHANGED
@@ -1,8 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
def
|
4 |
-
return "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
8 |
|
|
|
|
|
|
1 |
+
# import gradio as gr
|
2 |
+
|
3 |
+
# def greet(name):
|
4 |
+
# return "Hello " + name + "!!"
|
5 |
+
|
6 |
+
# demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
7 |
+
# demo.launch()
|
8 |
+
__all__ = ['label_func', 'learn', 'classify_image', 'categories', 'image', 'label', 'examples', 'intf']
|
9 |
+
|
10 |
+
# Cell
|
11 |
+
from fastai.vision.all import *
|
12 |
import gradio as gr
|
13 |
|
14 |
+
def label_func(x):
|
15 |
+
return "dog" if x[0].islower() else "cat"
|
16 |
+
# Cell
|
17 |
+
learn = load_learner('model.pkl')
|
18 |
+
|
19 |
+
# Cell
|
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 |
+
# Cell
|
27 |
+
image = gr.inputs.Image(shape=(192, 192))
|
28 |
+
label = gr.outputs.Label()
|
29 |
+
examples = ['dog1.jpeg', 'dog2.jpeg', 'dog3.jpeg']
|
30 |
|
31 |
+
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
32 |
+
intf.launch(inline=False)
|
dog1.jpeg
ADDED
dog2.jpeg
ADDED
dog3.jpeg
ADDED
model.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f55c963959fd63d56d9aaf56cc5bb08ebef0f846fa3f48731af32870ce1529f1
|
3 |
+
size 87559046
|