ju0im6bt6 commited on
Commit
52cdf1c
·
verified ·
1 Parent(s): c723091

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -4
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
- # Process video frames in real time using change event
38
- webrtc_input.change(
39
- fn=flip_vertically,
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
  )