Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -28,7 +28,7 @@ transform_image = transforms.Compose(
|
|
28 |
|
29 |
|
30 |
@spaces.GPU
|
31 |
-
def fn(vid, fps, color):
|
32 |
# Load the video using moviepy
|
33 |
video = mp.VideoFileClip(vid)
|
34 |
|
@@ -40,6 +40,7 @@ def fn(vid, fps, color):
|
|
40 |
|
41 |
# Process each frame for background removal
|
42 |
processed_frames = []
|
|
|
43 |
for frame in frames:
|
44 |
pil_image = Image.fromarray(frame)
|
45 |
processed_image = process(pil_image, color)
|
@@ -86,15 +87,6 @@ def process(image, color_hex):
|
|
86 |
return image
|
87 |
|
88 |
|
89 |
-
def process_file(f, color="#00FF00"):
|
90 |
-
name_path = f.rsplit(".", 1)[0] + ".png"
|
91 |
-
im = load_img(f, output_type="pil")
|
92 |
-
im = im.convert("RGB")
|
93 |
-
transparent = process(im, color)
|
94 |
-
transparent.save(name_path)
|
95 |
-
return name_path
|
96 |
-
|
97 |
-
|
98 |
with gr.Blocks() as demo:
|
99 |
with gr.Row():
|
100 |
in_video = gr.Video(label="Input Video")
|
@@ -105,13 +97,11 @@ with gr.Blocks() as demo:
|
|
105 |
fps_slider = gr.Slider(minimum=1, maximum=60, step=1, value=12, label="Output FPS")
|
106 |
color_picker = gr.ColorPicker(label="Background Color", value="#00FF00")
|
107 |
|
|
|
|
|
108 |
submit_button.click(
|
109 |
-
fn=lambda: gr.update(visible=True), inputs=None, outputs=[stream_image]
|
110 |
-
).then(
|
111 |
-
fn=lambda: gr.update(visible=False), inputs=None, outputs=[out_video],
|
112 |
-
).then(
|
113 |
fn, inputs=[in_video, fps_slider, color_picker], outputs=[stream_image, out_video]
|
114 |
)
|
115 |
-
|
116 |
if __name__ == "__main__":
|
117 |
demo.launch(show_error=True)
|
|
|
28 |
|
29 |
|
30 |
@spaces.GPU
|
31 |
+
def fn(vid, fps=12, color="#00FF00"):
|
32 |
# Load the video using moviepy
|
33 |
video = mp.VideoFileClip(vid)
|
34 |
|
|
|
40 |
|
41 |
# Process each frame for background removal
|
42 |
processed_frames = []
|
43 |
+
yield gr.update(visible=True), gr.update(visible=False)
|
44 |
for frame in frames:
|
45 |
pil_image = Image.fromarray(frame)
|
46 |
processed_image = process(pil_image, color)
|
|
|
87 |
return image
|
88 |
|
89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
with gr.Blocks() as demo:
|
91 |
with gr.Row():
|
92 |
in_video = gr.Video(label="Input Video")
|
|
|
97 |
fps_slider = gr.Slider(minimum=1, maximum=60, step=1, value=12, label="Output FPS")
|
98 |
color_picker = gr.ColorPicker(label="Background Color", value="#00FF00")
|
99 |
|
100 |
+
examples = gr.Examples(["rickroll-2sec.mp4"], inputs=in_video, outputs=[stream_image, out_video], fn=fn, cache_examples=True, cache_mode="lazy")
|
101 |
+
|
102 |
submit_button.click(
|
|
|
|
|
|
|
|
|
103 |
fn, inputs=[in_video, fps_slider, color_picker], outputs=[stream_image, out_video]
|
104 |
)
|
105 |
+
|
106 |
if __name__ == "__main__":
|
107 |
demo.launch(show_error=True)
|