Spaces:
Runtime error
Runtime error
jhj0517 commited on
Commit ·
62a455e
1
Parent(s): 3ccfbcb
Add create_filtered_video() and move logic to the inference class
Browse filesFiles changed (2)
- app.py+10-12
- modules/video_utils.py-1
10 unmodified lines1112131415161751 unmodified lines69707172737475767778798087 unmodified lines1681691701711721731741751761779 unmodified lines18718818919019119219319419519619719819910 unmodified linesfrom modules.utils import open_folderfrom modules.constants import (AUTOMATIC_MODE, BOX_PROMPT_MODE, PIXELIZE_FILTER, COLOR_FILTER, DEFAULT_COLOR,DEFAULT_PIXEL_SIZE)from modules.video_utils import extract_frames, get_frames_from_dir, clean_image_filesclass App:51 unmodified linesdef on_video_model_change(self,model_type: str,vid_input: str):output_temp_dir = TEMP_DIRclean_image_files(output_temp_dir)extract_frames(vid_input=vid_input, output_temp_dir=output_temp_dir)frames = get_frames_from_dir(vid_dir=output_temp_dir)initial_frame, max_frame_index = frames[0], (len(frames)-1)self.sam_inf.init_video_inference_state(vid_input=output_temp_dir, model_type=model_type)return [ImagePrompter(label="Prompt image with Box & Point", value=initial_frame),gr.Slider(label="Frame Index", value=0, interactive=True, step=1, minimum=0, maximum=max_frame_index)87 unmodified lineswith gr.Row():btn_generate = gr.Button("GENERATE", variant="primary")with gr.Row():gallery_output = gr.Gallery(label="Output images will be shown here")with gr.Column():output_file = gr.File(label="Generated psd file", scale=9)btn_open_folder = gr.Button("📁\nOpen PSD folder", scale=1)file_vid_input.change(fn=self.on_video_model_change,inputs=[dd_models, file_vid_input],9 unmodified linesoutputs=[cp_color_picker,nb_pixel_size])preview_params = [vid_frame_prompter, dd_filter_mode, sld_frame_selector, nb_pixel_size, cp_color_picker]btn_generate_preview.click(fn=self.sam_inf.add_filter_to_preview,inputs=preview_params,outputs=[img_preview])btn_generate.click(fn=self.sam_inf.add_filter_to_video,inputs=preview_params,outputs=None)self.demo.queue().launch(inbrowser=True)10 unmodified lines1112131415161751 unmodified lines69707172737475767787 unmodified lines1651661671681691701711721731749 unmodified lines18418518618718818919019119219319419519619710 unmodified linesfrom modules.utils import open_folderfrom modules.constants import (AUTOMATIC_MODE, BOX_PROMPT_MODE, PIXELIZE_FILTER, COLOR_FILTER, DEFAULT_COLOR,DEFAULT_PIXEL_SIZE)from modules.video_utils import extract_frames, extract_sound, get_frames_from_dir, clean_temp_dirclass App:51 unmodified linesdef on_video_model_change(self,model_type: str,vid_input: str):self.sam_inf.init_video_inference_state(vid_input=vid_input, model_type=model_type)frames = get_frames_from_dir(vid_dir=TEMP_DIR)initial_frame, max_frame_index = frames[0], (len(frames)-1)return [ImagePrompter(label="Prompt image with Box & Point", value=initial_frame),gr.Slider(label="Frame Index", value=0, interactive=True, step=1, minimum=0, maximum=max_frame_index)87 unmodified lineswith gr.Row():btn_generate = gr.Button("GENERATE", variant="primary")with gr.Row():vid_output = gr.Video(label="Output video")with gr.Column():output_file = gr.File(label="Downloadable Video Output File", scale=9)btn_open_folder = gr.Button("📁\nOpen Output folder", scale=1)file_vid_input.change(fn=self.on_video_model_change,inputs=[dd_models, file_vid_input],9 unmodified linesoutputs=[cp_color_picker,nb_pixel_size])preview_params = [vid_frame_prompter, dd_filter_mode, sld_frame_selector, nb_pixel_size,cp_color_picker]btn_generate_preview.click(fn=self.sam_inf.add_filter_to_preview,inputs=preview_params,outputs=[img_preview])btn_generate.click(fn=self.sam_inf.create_filtered_video,inputs=preview_params,outputs=[vid_output, output_file])self.demo.queue().launch(inbrowser=True)
237 unmodified lines238239240241237 unmodified linesos.remove(file_path)except Exception as e:logger.exception("Error while removing image files")raise RuntimeError(f"An error occurred: {str(e)}")237 unmodified lines238239240237 unmodified linesos.remove(file_path)except Exception as e:logger.exception("Error while removing image files")
app.py+10-12
modules/video_utils.py-1