Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -15,6 +15,7 @@ def paint(frame: np.ndarray) -> np.ndarray:
|
|
15 |
global canvas
|
16 |
h, w, _ = frame.shape
|
17 |
|
|
|
18 |
if canvas is None:
|
19 |
canvas = np.zeros((h, w, 3), dtype=np.uint8)
|
20 |
|
@@ -29,10 +30,11 @@ def paint(frame: np.ndarray) -> np.ndarray:
|
|
29 |
# Blend live frame and canvas
|
30 |
return cv2.addWeighted(frame, 0.5, canvas, 0.5, 0)
|
31 |
|
|
|
32 |
demo = gr.Interface(
|
33 |
fn=paint,
|
34 |
-
inputs=gr.
|
35 |
-
outputs=gr.
|
36 |
live=True,
|
37 |
title="🖌️ Virtual Painter",
|
38 |
description="Move your index finger in front of the camera to draw!"
|
|
|
15 |
global canvas
|
16 |
h, w, _ = frame.shape
|
17 |
|
18 |
+
# Initialize canvas once
|
19 |
if canvas is None:
|
20 |
canvas = np.zeros((h, w, 3), dtype=np.uint8)
|
21 |
|
|
|
30 |
# Blend live frame and canvas
|
31 |
return cv2.addWeighted(frame, 0.5, canvas, 0.5, 0)
|
32 |
|
33 |
+
# --- Gradio interface using gr.components ---
|
34 |
demo = gr.Interface(
|
35 |
fn=paint,
|
36 |
+
inputs=gr.components.Image(source="webcam", type="numpy"),
|
37 |
+
outputs=gr.components.Image(type="numpy"),
|
38 |
live=True,
|
39 |
title="🖌️ Virtual Painter",
|
40 |
description="Move your index finger in front of the camera to draw!"
|