diff --git a/scripts/t2v_helpers/args.py b/scripts/t2v_helpers/args.py index b952f5f..9f75dbd 100644 --- a/scripts/t2v_helpers/args.py +++ b/scripts/t2v_helpers/args.py @@ -41,29 +41,30 @@ def enable_sampler_dropdown(model_type): return gr.update(visible=is_visible) def setup_top_parts(mode, d): - with gr.Column(scale=3, variant='compact'): - with gr.Row(elem_id=f'{mode}_prompt_toprow'): - prompt = gr.Textbox(label='Prompt', lines=3, interactive=True, elem_id=f"{mode}_prompt", placeholder="Enter your prompt here...") - with gr.Row(elem_id=f'{mode}_n_prompt_toprow'): - n_prompt = gr.Textbox(label='Negative prompt', lines=2, interactive=True, elem_id=f"{mode}_n_prompt", value=d.n_prompt) - with gr.Column(scale=1, variant='compact'): - with gr.Row(elem_id=f"{mode}_generate_box", variant='compact', elem_classes="generate-box"): - interrupt = gr.Button('Interrupt', elem_id=f"{mode}_interrupt", elem_classes="generate-box-interrupt") - skip = gr.Button('Skip', elem_id=f"{mode}_skip", elem_classes="generate-box-skip") - run_button = gr.Button('Generate', elem_id=f"{mode}_generate", variant='primary') + with gr.Row(equal_height=False, variant='compact'): + with gr.Column(scale=4, variant='compact'): + with gr.Row(elem_id=f'{mode}_prompt_toprow'): + prompt = gr.Textbox(label='Prompt', show_label=False, lines=3, interactive=True, elem_id=f"{mode}_prompt", placeholder="Prompt (press Ctrl+Enter or Alt+Enter to generate)") + with gr.Row(elem_id=f'{mode}_n_prompt_toprow'): + n_prompt = gr.Textbox(label='Negative prompt', show_label=False, lines=2, interactive=True, elem_id=f"{mode}_n_prompt", value=d.n_prompt, placeholder="Negative prompt (press Ctrl+Enter or Alt+Enter to generate)") + with gr.Column(scale=1, variant='compact'): + with gr.Row(elem_id=f"{mode}_generate_box", variant='compact', elem_classes="generate-box"): + interrupt = gr.Button('Interrupt', elem_id=f"{mode}_interrupt", elem_classes="generate-box-interrupt") + skip = gr.Button('Skip', elem_id=f"{mode}_skip", elem_classes="generate-box-skip") + run_button = gr.Button('Generate', elem_id=f"{mode}_generate", variant='primary') - skip.click( - fn=lambda: shared.state.skip(), - inputs=[], - outputs=[], - ) + skip.click( + fn=lambda: shared.state.skip(), + inputs=[], + outputs=[], + ) - interrupt.click( - fn=lambda: shared.state.interrupt(), - inputs=[], - outputs=[], - ) - + interrupt.click( + fn=lambda: shared.state.interrupt(), + inputs=[], + outputs=[], + ) + return prompt, n_prompt, run_button def setup_common_values(mode, d): @@ -132,47 +133,48 @@ def setup_model_switcher(): def setup_tab(mode, d, model, model_type, process): prompt, n_prompt, run_button = setup_top_parts('txt2vid', d) - with gr.Column(scale=1, variant='compact'): - if mode == 'vid2vid': - with gr.Row(): - gr.HTML('Put your video here') - gr.HTML('Vid2vid for VideoCrafter is to be done!') - - vid2vid_frames = gr.File(label="Input video", interactive=True, file_count="single", file_types=["video"], elem_id="vid_to_vid_chosen_file") - with gr.Row(): - gr.HTML('Alternative: enter the relative (to the webui) path to the file') - with gr.Row(): - vid2vid_frames_path = gr.Textbox(label="Input video path", interactive=True, elem_id="vid_to_vid_chosen_path", placeholder='Enter your video path here, or upload in the box above ^') - - sampler, steps, seed, cfg_scale, width, height, eta, frames, batch_count = setup_common_values(mode, d) - if mode == 'vid2vid': - with gr.Row(): - strength = gr.Slider(label="denoising strength", value=d.strength, minimum=0, maximum=1, step=0.05, interactive=True) - vid2vid_startFrame=gr.Number(label='vid2vid start frame',value=d.vid2vid_startFrame) - model_type.change(fn=enable_sampler_dropdown, inputs=[model_type], outputs=[sampler]) - if mode == 'txt2vid': - with gr.Accordion('img2vid', open=False): - inpainting_image = gr.File(label="Inpainting image", interactive=True, file_count="single", file_types=["image"], elem_id="inpainting_chosen_file") - # TODO: should be tied to the total frame count dynamically - inpainting_frames=gr.Slider(label='inpainting frames',value=d.inpainting_frames,minimum=0, maximum=250, step=1) + with gr.Row(equal_height=False, variant='compact'): + with gr.Column(scale=1, variant='compact'): + if mode == 'vid2vid': with gr.Row(): - gr.Markdown('''`inpainting frames` is the number of frames inpainting is applied to (counting from the beginning) - - The following parameters are exposed in this keyframe: max frames as `max_f`, inpainting frames as `max_i_f`, current frame number as `t`, seed as `s` - - The weigths of `0:(t/max_i_f), "max_i_f":(1)` will *continue* the initial pic - - To *loop it back*, set the weight to 0 for the first and for the last frame - - Example: `0:(0), "max_i_f/4":(1), "3*max_i_f/4":(1), "max_i_f-1":(0)` ''') + gr.HTML('Put your video here') + gr.HTML('Vid2vid for VideoCrafter is to be done!') + + vid2vid_frames = gr.File(label="Input video", interactive=True, file_count="single", file_types=["video"], elem_id="vid_to_vid_chosen_file") with gr.Row(): - inpainting_weights = gr.Textbox(label="Inpainting weights", value=d.inpainting_weights, interactive=True) - with gr.Column(scale=1, variant='compact'): - output = gr.HTML(i1_store_t2v, elem_id='deforum_header') - - dummy_component1 = gr.Label("", visible=False) - dummy_component2 = gr.Label("", visible=False) - do_vid2vid = gr.State(value=1 if mode == 'vid2vid' else 0) + gr.HTML('Alternative: enter the relative (to the webui) path to the file') + with gr.Row(): + vid2vid_frames_path = gr.Textbox(label="Input video path", interactive=True, elem_id="vid_to_vid_chosen_path", placeholder='Enter your video path here, or upload in the box above ^') + + sampler, steps, seed, cfg_scale, width, height, eta, frames, batch_count = setup_common_values(mode, d) + if mode == 'vid2vid': + with gr.Row(): + strength = gr.Slider(label="denoising strength", value=d.strength, minimum=0, maximum=1, step=0.05, interactive=True) + vid2vid_startFrame=gr.Number(label='vid2vid start frame',value=d.vid2vid_startFrame) + model_type.change(fn=enable_sampler_dropdown, inputs=[model_type], outputs=[sampler]) + if mode == 'txt2vid': + with gr.Accordion('img2vid', open=False): + inpainting_image = gr.File(label="Inpainting image", interactive=True, file_count="single", file_types=["image"], elem_id="inpainting_chosen_file") + # TODO: should be tied to the total frame count dynamically + inpainting_frames=gr.Slider(label='inpainting frames',value=d.inpainting_frames,minimum=0, maximum=250, step=1) + with gr.Row(): + gr.Markdown('''`inpainting frames` is the number of frames inpainting is applied to (counting from the beginning) + + The following parameters are exposed in this keyframe: max frames as `max_f`, inpainting frames as `max_i_f`, current frame number as `t`, seed as `s` + + The weigths of `0:(t/max_i_f), "max_i_f":(1)` will *continue* the initial pic + + To *loop it back*, set the weight to 0 for the first and for the last frame + + Example: `0:(0), "max_i_f/4":(1), "3*max_i_f/4":(1), "max_i_f-1":(0)` ''') + with gr.Row(): + inpainting_weights = gr.Textbox(label="Inpainting weights", value=d.inpainting_weights, interactive=True) + with gr.Column(scale=1, variant='compact'): + output = gr.HTML(i1_store_t2v, elem_id='deforum_header') + + dummy_component1 = gr.Label("", visible=False) + dummy_component2 = gr.Label("", visible=False) + do_vid2vid = gr.State(value=1 if mode == 'vid2vid' else 0) components = locals() @@ -191,33 +193,35 @@ def setup_text2video_settings_dictionary(model, model_type, process): components_v2v = setup_tab(mode, d, model, model_type, process) with gr.Tab('Output settings'): - with gr.Row(variant='compact') as fps_out_format_row: - fps = gr.Slider(label="FPS", value=dv.fps, minimum=1, maximum=240, step=1) - with gr.Row(variant='compact') as soundtrack_row: - add_soundtrack = gr.Radio(['None', 'File', 'Init Video'], label="Add soundtrack", value=dv.add_soundtrack) - soundtrack_path = gr.Textbox(label="Soundtrack path", lines=1, interactive=True, value=dv.soundtrack_path) + with gr.Row(equal_height=False, variant='compact'): + with gr.Column(scale=1, variant='default'): + with gr.Row(variant='compact') as fps_out_format_row: + fps = gr.Slider(label="FPS", value=dv.fps, minimum=1, maximum=240, step=1) + with gr.Row(variant='compact') as soundtrack_row: + add_soundtrack = gr.Radio(['None', 'File', 'Init Video'], label="Add soundtrack", value=dv.add_soundtrack) + soundtrack_path = gr.Textbox(label="Soundtrack path", lines=1, interactive=True, value=dv.soundtrack_path) - with gr.Row(variant='compact'): - skip_video_creation = gr.Checkbox(label="Skip video creation", value=dv.skip_video_creation, interactive=True) - with gr.Row(equal_height=True, variant='compact', visible=True) as ffmpeg_set_row: - ffmpeg_crf = gr.Slider(minimum=0, maximum=51, step=1, label="CRF", value=dv.ffmpeg_crf, interactive=True) - ffmpeg_preset = gr.Dropdown(label="Preset", choices=['veryslow', 'slower', 'slow', 'medium', 'fast', 'faster', 'veryfast', 'superfast', 'ultrafast'], interactive=True, value=dv.ffmpeg_preset, type="value") - with gr.Row(equal_height=True, variant='compact', visible=True) as ffmpeg_location_row: - ffmpeg_location = gr.Textbox(label="Location", lines=1, interactive=True, value=dv.ffmpeg_location) - with gr.Accordion(label='Metadata viewer', open=False, visible=True): - with gr.Row(variant='compact'): - metadata_file = gr.File(label="Video", interactive=True, file_count="single", file_types=["video"], elem_id="metadata_chosen_file") - with gr.Row(variant='compact'): - metadata_btn = gr.Button(value='Get metadata') - with gr.Row(variant='compact'): - metadata_box = gr.HTML() - - def get_metadata(file): - print('Reading metadata') - video = MP4(file.name) - return video["\xa9cmt"] + with gr.Row(variant='compact'): + skip_video_creation = gr.Checkbox(label="Skip video creation", value=dv.skip_video_creation, interactive=True) + with gr.Row(equal_height=True, variant='compact', visible=True) as ffmpeg_set_row: + ffmpeg_crf = gr.Slider(minimum=0, maximum=51, step=1, label="CRF", value=dv.ffmpeg_crf, interactive=True) + ffmpeg_preset = gr.Dropdown(label="Preset", choices=['veryslow', 'slower', 'slow', 'medium', 'fast', 'faster', 'veryfast', 'superfast', 'ultrafast'], interactive=True, value=dv.ffmpeg_preset, type="value") + with gr.Row(equal_height=True, variant='compact', visible=True) as ffmpeg_location_row: + ffmpeg_location = gr.Textbox(label="Location", lines=1, interactive=True, value=dv.ffmpeg_location) + with gr.Column(scale=1, variant='default'): + with gr.Row(variant='compact'): + metadata_file = gr.File(label="Video", interactive=True, file_count="single", file_types=["video"], elem_id="metadata_chosen_file") + with gr.Row(variant='compact'): + metadata_btn = gr.Button(value='View metadata') + with gr.Row(variant='compact'): + metadata_box = gr.HTML() + + def get_metadata(file): + print('Reading metadata') + video = MP4(file.name) + return video["\xa9cmt"] - metadata_btn.click(get_metadata, inputs=[metadata_file], outputs=[metadata_box]) + metadata_btn.click(get_metadata, inputs=[metadata_file], outputs=[metadata_box]) with gr.Tab('How to install? Where to get help, how to help?'): gr.Markdown(welcome_text)