Input Sanitization
Browse files
app.py
CHANGED
@@ -6,6 +6,7 @@ import mediapipe as mp
|
|
6 |
import time
|
7 |
import gradio as gr
|
8 |
import glob
|
|
|
9 |
|
10 |
width_, height_ = 144, 96
|
11 |
|
@@ -16,8 +17,20 @@ output_frames = []
|
|
16 |
|
17 |
|
18 |
def is_hex(hexq):
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
else:
|
22 |
return False
|
23 |
|
@@ -80,7 +93,7 @@ def clear(landmarks): # brute force finger orientation checking
|
|
80 |
return False
|
81 |
|
82 |
|
83 |
-
def show(video, dominant_hand, hex_color): # main
|
84 |
cam = cv2.VideoCapture(video) # get the video file from path
|
85 |
width = cam.get(cv2.CAP_PROP_FRAME_WIDTH)
|
86 |
height = cam.get(cv2.CAP_PROP_FRAME_HEIGHT)
|
@@ -190,6 +203,7 @@ def show(video, dominant_hand, hex_color): # main
|
|
190 |
for filename in glob.glob('*.png'):
|
191 |
imggg = cv2.imread(filename)
|
192 |
img_array.append(imggg)
|
|
|
193 |
|
194 |
video_output = cv2.VideoWriter('any.webm', cv2.VideoWriter_fourcc(*'VP80'), 30, (640, 480))
|
195 |
|
@@ -199,12 +213,15 @@ def show(video, dominant_hand, hex_color): # main
|
|
199 |
|
200 |
return 'any.webm'
|
201 |
|
|
|
202 |
title = 'Air Draw'
|
203 |
-
desc = 'A mediapipe hands wrapper for drawing in the air.
|
|
|
|
|
204 |
iface = gr.Interface(
|
205 |
fn=show,
|
206 |
inputs=[
|
207 |
-
gr.inputs.Video(source="webcam", label="Record yourself drawing
|
208 |
gr.inputs.Radio(['Right', 'Left'], label="Dominant Hand"),
|
209 |
gr.inputs.Textbox(placeholder="#355C7D", label="Hex Color")
|
210 |
],
|
|
|
6 |
import time
|
7 |
import gradio as gr
|
8 |
import glob
|
9 |
+
import os
|
10 |
|
11 |
width_, height_ = 144, 96
|
12 |
|
|
|
17 |
|
18 |
|
19 |
def is_hex(hexq):
|
20 |
+
valid = ['0','1','2','3','4','5','6',
|
21 |
+
'7','8','9','A','a','B','b',
|
22 |
+
'C','c','D','d','E','e','F',
|
23 |
+
'f']
|
24 |
+
hexq = str(hexq)
|
25 |
+
if len(hexq) == 7:
|
26 |
+
if hexq[0] == '#':
|
27 |
+
for h in hexq[1:]:
|
28 |
+
if h in valid:
|
29 |
+
return True
|
30 |
+
else:
|
31 |
+
return False
|
32 |
+
else:
|
33 |
+
return False
|
34 |
else:
|
35 |
return False
|
36 |
|
|
|
93 |
return False
|
94 |
|
95 |
|
96 |
+
def show(video, dominant_hand, hex_color='#FFFFFF'): # main
|
97 |
cam = cv2.VideoCapture(video) # get the video file from path
|
98 |
width = cam.get(cv2.CAP_PROP_FRAME_WIDTH)
|
99 |
height = cam.get(cv2.CAP_PROP_FRAME_HEIGHT)
|
|
|
203 |
for filename in glob.glob('*.png'):
|
204 |
imggg = cv2.imread(filename)
|
205 |
img_array.append(imggg)
|
206 |
+
os.remove(filename)
|
207 |
|
208 |
video_output = cv2.VideoWriter('any.webm', cv2.VideoWriter_fourcc(*'VP80'), 30, (640, 480))
|
209 |
|
|
|
213 |
|
214 |
return 'any.webm'
|
215 |
|
216 |
+
|
217 |
title = 'Air Draw'
|
218 |
+
desc = 'A mediapipe hands wrapper for drawing in the air. Draw holding an invisible pen, ' \
|
219 |
+
'and open up your hand to lift the "pen" from the "paper". Use a "thumbs up" gesture to clear the drawing ' \
|
220 |
+
'paper. '
|
221 |
iface = gr.Interface(
|
222 |
fn=show,
|
223 |
inputs=[
|
224 |
+
gr.inputs.Video(source="webcam", label="Record yourself drawing holding an invisible pen!"),
|
225 |
gr.inputs.Radio(['Right', 'Left'], label="Dominant Hand"),
|
226 |
gr.inputs.Textbox(placeholder="#355C7D", label="Hex Color")
|
227 |
],
|