Armanul commited on
Commit
0a34ce4
·
verified ·
1 Parent(s): 0cada8e

Update app.py

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