cls00 commited on
Commit
b1070c2
·
1 Parent(s): 348c818

image classifier app

Browse files
Files changed (1) hide show
  1. app.py +33 -5
app.py CHANGED
@@ -1,7 +1,35 @@
1
- import gradio as gr
2
 
3
- def greet(name):
4
- return "Hello " + name + "!"
5
 
6
- iface = gr.Interface(fn=greet, inputs='text', outputs='text')
7
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # AUTOGENERATED! DO NOT EDIT! File to edit: ../app.ipynb.
2
 
3
+ # %% auto 0
4
+ __all__ = ['learn', 'categories', 'im_size', 'examples', 'intf', 'classify_image']
5
 
6
+ # %% ../app.ipynb 4
7
+ learn = load_learner('ft_resnet18_10epochs.pkl')
8
+
9
+ # %% ../app.ipynb 6
10
+ categories = ['city','town','countryside','ocean']
11
+
12
+ def classify_image(img):
13
+ pred, idx, probs = learn.predict(img)
14
+ ret = dict(
15
+ zip(categories,
16
+ map(float,probs)
17
+ )
18
+ )
19
+ return ret
20
+
21
+ # %% ../app.ipynb 8
22
+ im_size = 192
23
+
24
+ #image = gr.inputs.Image(shape=(im_size,im_size))
25
+ #label = gr.outputs.Label()
26
+ examples = ['images/test/035cd8f1-2c9c-45ac-9d67-e0b80043ef22.jpg',
27
+ 'images/test/b8f604be-44c2-4ad1-badd-f9c2ed0b2b13.jpg',
28
+ 'images/test/92358e88-e4cd-4cd8-87dd-bfa90d0a861e.jpg',
29
+ 'images/test/a9614023-dae6-437e-ae88-4677e9035a1d.jpg']
30
+
31
+ intf = gr.Interface(fn=classify_image,
32
+ inputs="image",
33
+ outputs="label",
34
+ examples=examples)
35
+ intf.launch(inline=False)