Update app.py
Browse files
app.py
CHANGED
@@ -76,7 +76,7 @@ def process_frame(frame, bg_type, bg, fast_mode, bg_frame_index, background_fram
|
|
76 |
return frame, bg_frame_index
|
77 |
|
78 |
@spaces.GPU
|
79 |
-
def fn(vid, bg_type="Color", bg_image=None, bg_video=None, color="#00FF00", fps=0, video_handling="slow_down", fast_mode=True):
|
80 |
try:
|
81 |
start_time = time.time() # Start the timer
|
82 |
|
@@ -110,8 +110,8 @@ def fn(vid, bg_type="Color", bg_image=None, bg_video=None, color="#00FF00", fps=
|
|
110 |
|
111 |
bg_frame_index = 0 # Initialize background frame index
|
112 |
|
113 |
-
# Use ThreadPoolExecutor for parallel processing
|
114 |
-
with ThreadPoolExecutor(max_workers=
|
115 |
futures = [executor.submit(process_frame, frames[i], bg_type, bg_image, fast_mode, bg_frame_index, background_frames, color) for i in range(len(frames))]
|
116 |
for future in futures:
|
117 |
result, bg_frame_index = future.result()
|
@@ -193,6 +193,8 @@ with gr.Blocks(theme=gr.themes.Ocean()) as demo:
|
|
193 |
with gr.Column(visible=False) as video_handling_options:
|
194 |
video_handling_radio = gr.Radio(["slow_down", "loop"], label="Video Handling", value="slow_down", interactive=True)
|
195 |
fast_mode_checkbox = gr.Checkbox(label="Fast Mode (Use BiRefNet_lite)", value=True, interactive=True)
|
|
|
|
|
196 |
time_textbox = gr.Textbox(label="Time Elapsed", interactive=False) # Add time textbox
|
197 |
|
198 |
def update_visibility(bg_type):
|
@@ -225,7 +227,7 @@ with gr.Blocks(theme=gr.themes.Ocean()) as demo:
|
|
225 |
|
226 |
submit_button.click(
|
227 |
fn,
|
228 |
-
inputs=[in_video, bg_type, bg_image, bg_video, color_picker, fps_slider, video_handling_radio, fast_mode_checkbox],
|
229 |
outputs=[stream_image, out_video, time_textbox],
|
230 |
)
|
231 |
|
|
|
76 |
return frame, bg_frame_index
|
77 |
|
78 |
@spaces.GPU
|
79 |
+
def fn(vid, bg_type="Color", bg_image=None, bg_video=None, color="#00FF00", fps=0, video_handling="slow_down", fast_mode=True, max_workers=8):
|
80 |
try:
|
81 |
start_time = time.time() # Start the timer
|
82 |
|
|
|
110 |
|
111 |
bg_frame_index = 0 # Initialize background frame index
|
112 |
|
113 |
+
# Use ThreadPoolExecutor for parallel processing with specified max_workers
|
114 |
+
with ThreadPoolExecutor(max_workers=min(max_workers, 32)) as executor: # Limit max_workers to 32
|
115 |
futures = [executor.submit(process_frame, frames[i], bg_type, bg_image, fast_mode, bg_frame_index, background_frames, color) for i in range(len(frames))]
|
116 |
for future in futures:
|
117 |
result, bg_frame_index = future.result()
|
|
|
193 |
with gr.Column(visible=False) as video_handling_options:
|
194 |
video_handling_radio = gr.Radio(["slow_down", "loop"], label="Video Handling", value="slow_down", interactive=True)
|
195 |
fast_mode_checkbox = gr.Checkbox(label="Fast Mode (Use BiRefNet_lite)", value=True, interactive=True)
|
196 |
+
max_workers_slider = gr.Slider( minimum=1, maximum=32, step=1, value=8, label="Max Workers", info="Determines how many Franes to process parallel", interactive=True
|
197 |
+
)
|
198 |
time_textbox = gr.Textbox(label="Time Elapsed", interactive=False) # Add time textbox
|
199 |
|
200 |
def update_visibility(bg_type):
|
|
|
227 |
|
228 |
submit_button.click(
|
229 |
fn,
|
230 |
+
inputs=[in_video, bg_type, bg_image, bg_video, color_picker, fps_slider, video_handling_radio, fast_mode_checkbox, max_workers_slider],
|
231 |
outputs=[stream_image, out_video, time_textbox],
|
232 |
)
|
233 |
|