abrar-adnan commited on
Commit
ab3729c
1 Parent(s): 6f0e285

app.py updated

Browse files
Files changed (1) hide show
  1. app.py +41 -4
app.py CHANGED
@@ -1,7 +1,44 @@
 
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
+ from fastai.vision.all import *
2
  import gradio as gr
3
 
 
 
4
 
5
+ cap_labels = (
6
+ 'balaclava cap',
7
+ 'baseball cap',
8
+ 'beanie cap',
9
+ 'boater hat',
10
+ 'bowler hat',
11
+ 'bucket hat',
12
+ 'cowboy hat',
13
+ 'fedora cap',
14
+ 'flat cap',
15
+ 'ivy cap',
16
+ 'kepi cap',
17
+ 'newsboy cap',
18
+ 'pork pie hat',
19
+ 'rasta cap',
20
+ 'sun hat',
21
+ 'taqiyah cap',
22
+ 'top hat',
23
+ 'trucker cap',
24
+ 'turban cap',
25
+ 'visor cap'
26
+ )
27
+
28
+ model = load_learner('cap-recognizer-v1.pkl')
29
+
30
+ def recognize_image(image):
31
+ pred, idx, probs = model.predict(image)
32
+ return dict(zip(cap_labels, map(float, probs)))
33
+
34
+ image = gr.inputs.Image(shape=(192,192))
35
+ label = gr.outputs.Label(num_top_classes=5)
36
+ examples = [
37
+ 'unknown_00.jpg',
38
+ 'unknown_01.jpg',
39
+ 'unknown_02.jpg',
40
+ 'unknown_03.jpg'
41
+ ]
42
+
43
+ iface = gr.Interface(fn=recognize_image, inputs=image, outputs=label, examples=examples)
44
+ iface.launch(inline=False)