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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -3
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import gradio as gr
2
  import numpy as np
3
  from fastrtc import WebRTC
 
4
 
5
  # WebRTC configuration with public STUN servers
6
  rtc_configuration = {
@@ -16,12 +17,15 @@ def flip_vertically(image):
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:
@@ -49,7 +53,6 @@ with gr.Blocks() as demo:
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
  )
54
 
55
  # Launch the app
 
1
  import gradio as gr
2
  import numpy as np
3
  from fastrtc import WebRTC
4
+ import time
5
 
6
  # WebRTC configuration with public STUN servers
7
  rtc_configuration = {
 
17
 
18
  # Server-side function to process video stream
19
  def process_stream(webrtc_input):
20
+ while True:
21
+ # Get the next frame from the WebRTC input
22
+ frame = next(webrtc_input, None)
23
  if frame is not None:
24
  # Process the frame (e.g., flip vertically)
25
  processed_frame = flip_vertically(frame)
26
  yield processed_frame
27
+ # Control frame rate (e.g., process every 0.1 seconds)
28
+ time.sleep(0.1)
29
 
30
  # Gradio app setup
31
  with gr.Blocks() as demo:
 
53
  inputs=[webrtc_input],
54
  outputs=[webrtc_output],
55
  queue=True,
 
56
  )
57
 
58
  # Launch the app