Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -38,7 +38,7 @@ def process_frame(frame, bg_type, bg, fast_mode, bg_frame_index, background_fram
|
|
| 38 |
elif bg_type == "Image":
|
| 39 |
processed_image = process(pil_image, bg, fast_mode)
|
| 40 |
elif bg_type == "Video":
|
| 41 |
-
background_frame = background_frames[bg_frame_index
|
| 42 |
bg_frame_index += 1
|
| 43 |
background_image = Image.fromarray(background_frame)
|
| 44 |
processed_image = process(pil_image, background_image, fast_mode)
|
|
@@ -77,12 +77,13 @@ def fn(vid, bg_type="Color", bg_image=None, bg_video=None, color="#00FF00", fps=
|
|
| 77 |
bg_frame_index = 0 # Initialize background frame index
|
| 78 |
|
| 79 |
with ThreadPoolExecutor(max_workers=max_workers) as executor:
|
| 80 |
-
|
| 81 |
-
for
|
| 82 |
-
|
|
|
|
| 83 |
processed_frames.append(result)
|
| 84 |
elapsed_time = time.time() - start_time
|
| 85 |
-
yield result, None, f"Processing frame {len(
|
| 86 |
|
| 87 |
processed_video = mp.ImageSequenceClip(processed_frames, fps=fps)
|
| 88 |
processed_video = processed_video.set_audio(audio)
|
|
@@ -187,4 +188,4 @@ with gr.Blocks(theme=gr.themes.Ocean()) as demo:
|
|
| 187 |
)
|
| 188 |
|
| 189 |
if __name__ == "__main__":
|
| 190 |
-
demo.launch(show_error=True)
|
|
|
|
| 38 |
elif bg_type == "Image":
|
| 39 |
processed_image = process(pil_image, bg, fast_mode)
|
| 40 |
elif bg_type == "Video":
|
| 41 |
+
background_frame = background_frames[bg_frame_index] # Access the correct background frame
|
| 42 |
bg_frame_index += 1
|
| 43 |
background_image = Image.fromarray(background_frame)
|
| 44 |
processed_image = process(pil_image, background_image, fast_mode)
|
|
|
|
| 77 |
bg_frame_index = 0 # Initialize background frame index
|
| 78 |
|
| 79 |
with ThreadPoolExecutor(max_workers=max_workers) as executor:
|
| 80 |
+
# Pass bg_frame_index as part of the function arguments
|
| 81 |
+
futures = [executor.submit(process_frame, frames[i], bg_type, bg_image, fast_mode, bg_frame_index + i, background_frames, color) for i in range(len(frames))]
|
| 82 |
+
for i, future in enumerate(futures):
|
| 83 |
+
result, _ = future.result() # No need to update bg_frame_index here
|
| 84 |
processed_frames.append(result)
|
| 85 |
elapsed_time = time.time() - start_time
|
| 86 |
+
yield result, None, f"Processing frame {i+1}/{len(frames)}... Elapsed time: {elapsed_time:.2f} seconds"
|
| 87 |
|
| 88 |
processed_video = mp.ImageSequenceClip(processed_frames, fps=fps)
|
| 89 |
processed_video = processed_video.set_audio(audio)
|
|
|
|
| 188 |
)
|
| 189 |
|
| 190 |
if __name__ == "__main__":
|
| 191 |
+
demo.launch(show_error=True)
|