Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -44,6 +44,7 @@ def fn(vid, fps, color):
|
|
44 |
pil_image = Image.fromarray(frame)
|
45 |
processed_image = process(pil_image, color)
|
46 |
processed_frames.append(np.array(processed_image))
|
|
|
47 |
|
48 |
# Create a new video from the processed frames
|
49 |
processed_video = mp.ImageSequenceClip(processed_frames, fps=fps)
|
@@ -59,7 +60,7 @@ def fn(vid, fps, color):
|
|
59 |
processed_video.write_videofile(temp_filepath, codec="libx264")
|
60 |
|
61 |
# Return the path to the temporary file
|
62 |
-
|
63 |
|
64 |
|
65 |
def process(image, color_hex):
|
@@ -96,14 +97,19 @@ def process_file(f, color="#00FF00"):
|
|
96 |
with gr.Blocks() as demo:
|
97 |
with gr.Row():
|
98 |
in_video = gr.Video(label="Input Video")
|
99 |
-
|
|
|
100 |
submit_button = gr.Button("Change Background")
|
101 |
with gr.Row():
|
102 |
fps_slider = gr.Slider(minimum=1, maximum=60, step=1, value=12, label="Output FPS")
|
103 |
color_picker = gr.ColorPicker(label="Background Color", value="#00FF00")
|
104 |
|
105 |
submit_button.click(
|
106 |
-
fn, inputs=
|
|
|
|
|
|
|
|
|
107 |
)
|
108 |
|
109 |
if __name__ == "__main__":
|
|
|
44 |
pil_image = Image.fromarray(frame)
|
45 |
processed_image = process(pil_image, color)
|
46 |
processed_frames.append(np.array(processed_image))
|
47 |
+
yield processed_image, gr.update(visible=False)
|
48 |
|
49 |
# Create a new video from the processed frames
|
50 |
processed_video = mp.ImageSequenceClip(processed_frames, fps=fps)
|
|
|
60 |
processed_video.write_videofile(temp_filepath, codec="libx264")
|
61 |
|
62 |
# Return the path to the temporary file
|
63 |
+
yield gr.update(visible=False), temp_filepath
|
64 |
|
65 |
|
66 |
def process(image, color_hex):
|
|
|
97 |
with gr.Blocks() as demo:
|
98 |
with gr.Row():
|
99 |
in_video = gr.Video(label="Input Video")
|
100 |
+
stream_image = gr.Image(label="Streaming Output")
|
101 |
+
out_video = gr.Video(label="Final Output Video")
|
102 |
submit_button = gr.Button("Change Background")
|
103 |
with gr.Row():
|
104 |
fps_slider = gr.Slider(minimum=1, maximum=60, step=1, value=12, label="Output FPS")
|
105 |
color_picker = gr.ColorPicker(label="Background Color", value="#00FF00")
|
106 |
|
107 |
submit_button.click(
|
108 |
+
fn=lambda: gr.update(visible=True), inputs=None, outputs=[stream_image]
|
109 |
+
).then(
|
110 |
+
fn=lambda: gr.update(visible=False), inputs=None, outputs=[out_video],
|
111 |
+
).then(
|
112 |
+
fn, inputs=[in_video, fps_slider, color_picker], outputs=[stream_image, out_video]
|
113 |
)
|
114 |
|
115 |
if __name__ == "__main__":
|