tripathysagar commited on
Commit
7fa0587
1 Parent(s): dc61a7a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +75 -0
app.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # coding: utf-8
3
+
4
+ # In[1]:
5
+
6
+
7
+ from fastai.vision.all import *
8
+ import gradio as gr
9
+ import os
10
+
11
+
12
+ # In[ ]:
13
+
14
+
15
+ from pathlib import Path
16
+ from fastcore.xtras import Path
17
+ from fastai.learner import load_learner
18
+ from fastcore.foundation import L
19
+
20
+
21
+ # In[2]:
22
+
23
+
24
+ img_path = Path('./static')
25
+ images_lis = [ i for i in list(img_path.ls()) if i.is_file()]
26
+ images_lis[:3], len(images_lis)
27
+
28
+
29
+ # In[3]:
30
+
31
+
32
+ def label_to_class(f:str)->L:
33
+ return L(f)
34
+
35
+
36
+ # In[4]:
37
+
38
+
39
+ learner = load_learner('./model/asl_sign_multi_resnet18_03.pkl')
40
+
41
+
42
+ # In[ ]:
43
+
44
+
45
+ def pred_image(image):
46
+ dict = {}
47
+ for i, j in zip(learner.dls.vocab, learner.predict(image)[2]):
48
+ dict[i] = round(j.item(), 2)
49
+
50
+ return dict
51
+
52
+
53
+ demo = gr.Interface(
54
+ fn=pred_image,
55
+ inputs='image',
56
+ outputs=gr.Label(num_top_classes=29),
57
+ examples=images_lis,
58
+ )
59
+
60
+ if __name__ == "__main__":
61
+ demo.launch(debug=True)
62
+
63
+
64
+
65
+ # In[ ]:
66
+
67
+
68
+
69
+
70
+
71
+ # In[ ]:
72
+
73
+
74
+
75
+