Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -14,6 +14,15 @@ rtc_configuration = {
|
|
14 |
def flip_vertically(image):
|
15 |
return np.flip(image, axis=0)
|
16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
# Gradio app setup
|
18 |
with gr.Blocks() as demo:
|
19 |
gr.HTML("<h1 style='text-align: center'>Real-Time Webcam Stream with FastRTC</h1>")
|
@@ -34,12 +43,11 @@ with gr.Blocks() as demo:
|
|
34 |
rtc_configuration=rtc_configuration,
|
35 |
)
|
36 |
|
37 |
-
#
|
38 |
-
|
39 |
-
fn=
|
40 |
inputs=[webrtc_input],
|
41 |
outputs=[webrtc_output],
|
42 |
-
_js="() => {}", # Ensures continuous streaming
|
43 |
queue=True,
|
44 |
every=0.1, # Process frames every 0.1 seconds for real-time effect
|
45 |
)
|
|
|
14 |
def flip_vertically(image):
|
15 |
return np.flip(image, axis=0)
|
16 |
|
17 |
+
# Server-side function to process video stream
|
18 |
+
def process_stream(webrtc_input):
|
19 |
+
# This function will receive frames from the WebRTC input
|
20 |
+
for frame in webrtc_input:
|
21 |
+
if frame is not None:
|
22 |
+
# Process the frame (e.g., flip vertically)
|
23 |
+
processed_frame = flip_vertically(frame)
|
24 |
+
yield processed_frame
|
25 |
+
|
26 |
# Gradio app setup
|
27 |
with gr.Blocks() as demo:
|
28 |
gr.HTML("<h1 style='text-align: center'>Real-Time Webcam Stream with FastRTC</h1>")
|
|
|
43 |
rtc_configuration=rtc_configuration,
|
44 |
)
|
45 |
|
46 |
+
# Connect input to output through the processing function
|
47 |
+
demo.load(
|
48 |
+
fn=process_stream,
|
49 |
inputs=[webrtc_input],
|
50 |
outputs=[webrtc_output],
|
|
|
51 |
queue=True,
|
52 |
every=0.1, # Process frames every 0.1 seconds for real-time effect
|
53 |
)
|