Spaces:
Running
Running
jhj0517
commited on
Commit
β’
62a455e
1
Parent(s):
3ccfbcb
Add create_filtered_video() and move logic to the inference class
Browse files- app.py +10 -12
- modules/video_utils.py +0 -1
app.py
CHANGED
@@ -11,7 +11,7 @@ from modules.paths import (OUTPUT_DIR, OUTPUT_PSD_DIR, SAM2_CONFIGS_DIR, TEMP_DI
|
|
11 |
from modules.utils import open_folder
|
12 |
from modules.constants import (AUTOMATIC_MODE, BOX_PROMPT_MODE, PIXELIZE_FILTER, COLOR_FILTER, DEFAULT_COLOR,
|
13 |
DEFAULT_PIXEL_SIZE)
|
14 |
-
from modules.video_utils import extract_frames, get_frames_from_dir,
|
15 |
|
16 |
|
17 |
class App:
|
@@ -69,12 +69,9 @@ class App:
|
|
69 |
def on_video_model_change(self,
|
70 |
model_type: str,
|
71 |
vid_input: str):
|
72 |
-
|
73 |
-
|
74 |
-
extract_frames(vid_input=vid_input, output_temp_dir=output_temp_dir)
|
75 |
-
frames = get_frames_from_dir(vid_dir=output_temp_dir)
|
76 |
initial_frame, max_frame_index = frames[0], (len(frames)-1)
|
77 |
-
self.sam_inf.init_video_inference_state(vid_input=output_temp_dir, model_type=model_type)
|
78 |
return [
|
79 |
ImagePrompter(label="Prompt image with Box & Point", value=initial_frame),
|
80 |
gr.Slider(label="Frame Index", value=0, interactive=True, step=1, minimum=0, maximum=max_frame_index)
|
@@ -168,10 +165,10 @@ class App:
|
|
168 |
with gr.Row():
|
169 |
btn_generate = gr.Button("GENERATE", variant="primary")
|
170 |
with gr.Row():
|
171 |
-
|
172 |
with gr.Column():
|
173 |
-
output_file = gr.File(label="
|
174 |
-
btn_open_folder = gr.Button("π\nOpen
|
175 |
|
176 |
file_vid_input.change(fn=self.on_video_model_change,
|
177 |
inputs=[dd_models, file_vid_input],
|
@@ -187,13 +184,14 @@ class App:
|
|
187 |
outputs=[cp_color_picker,
|
188 |
nb_pixel_size])
|
189 |
|
190 |
-
preview_params = [vid_frame_prompter, dd_filter_mode, sld_frame_selector, nb_pixel_size,
|
|
|
191 |
btn_generate_preview.click(fn=self.sam_inf.add_filter_to_preview,
|
192 |
inputs=preview_params,
|
193 |
outputs=[img_preview])
|
194 |
-
btn_generate.click(fn=self.sam_inf.
|
195 |
inputs=preview_params,
|
196 |
-
outputs=
|
197 |
|
198 |
self.demo.queue().launch(inbrowser=True)
|
199 |
|
|
|
11 |
from modules.utils import open_folder
|
12 |
from modules.constants import (AUTOMATIC_MODE, BOX_PROMPT_MODE, PIXELIZE_FILTER, COLOR_FILTER, DEFAULT_COLOR,
|
13 |
DEFAULT_PIXEL_SIZE)
|
14 |
+
from modules.video_utils import extract_frames, extract_sound, get_frames_from_dir, clean_temp_dir
|
15 |
|
16 |
|
17 |
class App:
|
|
|
69 |
def on_video_model_change(self,
|
70 |
model_type: str,
|
71 |
vid_input: str):
|
72 |
+
self.sam_inf.init_video_inference_state(vid_input=vid_input, model_type=model_type)
|
73 |
+
frames = get_frames_from_dir(vid_dir=TEMP_DIR)
|
|
|
|
|
74 |
initial_frame, max_frame_index = frames[0], (len(frames)-1)
|
|
|
75 |
return [
|
76 |
ImagePrompter(label="Prompt image with Box & Point", value=initial_frame),
|
77 |
gr.Slider(label="Frame Index", value=0, interactive=True, step=1, minimum=0, maximum=max_frame_index)
|
|
|
165 |
with gr.Row():
|
166 |
btn_generate = gr.Button("GENERATE", variant="primary")
|
167 |
with gr.Row():
|
168 |
+
vid_output = gr.Video(label="Output video")
|
169 |
with gr.Column():
|
170 |
+
output_file = gr.File(label="Downloadable Video Output File", scale=9)
|
171 |
+
btn_open_folder = gr.Button("π\nOpen Output folder", scale=1)
|
172 |
|
173 |
file_vid_input.change(fn=self.on_video_model_change,
|
174 |
inputs=[dd_models, file_vid_input],
|
|
|
184 |
outputs=[cp_color_picker,
|
185 |
nb_pixel_size])
|
186 |
|
187 |
+
preview_params = [vid_frame_prompter, dd_filter_mode, sld_frame_selector, nb_pixel_size,
|
188 |
+
cp_color_picker]
|
189 |
btn_generate_preview.click(fn=self.sam_inf.add_filter_to_preview,
|
190 |
inputs=preview_params,
|
191 |
outputs=[img_preview])
|
192 |
+
btn_generate.click(fn=self.sam_inf.create_filtered_video,
|
193 |
inputs=preview_params,
|
194 |
+
outputs=[vid_output, output_file])
|
195 |
|
196 |
self.demo.queue().launch(inbrowser=True)
|
197 |
|
modules/video_utils.py
CHANGED
@@ -238,4 +238,3 @@ def _clean_files_with_extension(dir_path: str, extensions: List):
|
|
238 |
os.remove(file_path)
|
239 |
except Exception as e:
|
240 |
logger.exception("Error while removing image files")
|
241 |
-
raise RuntimeError(f"An error occurred: {str(e)}")
|
|
|
238 |
os.remove(file_path)
|
239 |
except Exception as e:
|
240 |
logger.exception("Error while removing image files")
|
|