|
1 | 1 | import os, argparse |
2 | 2 | import sys |
3 | 3 | import gradio as gr |
| 4 | +import random |
4 | 5 | from scripts.gradio.i2v_test_application import Image2Video |
5 | 6 | sys.path.insert(1, os.path.join(sys.path[0], 'lvdm')) |
6 | 7 |
|
|
16 | 17 | ['prompts/512_loop/40.png', 'flowers swaying in the wind', 50, 7.5, 1.0, 5, 234], |
17 | 18 | ] |
18 | 19 |
|
| 20 | +max_seed = 2 ** 31 |
19 | 21 |
|
20 | 22 |
|
21 | 23 | def dynamicrafter_demo(result_dir='./tmp/', res=512): |
22 | 24 | if res == 1024: |
23 | 25 | resolution = '576_1024' |
24 | | - css = """#input_img {max-width: 1024px !important} #output_vid {max-width: 1024px; max-height:576px}""" |
| 26 | + css = """#input_img {max-width: 1024px !important} #output_vid {max-width: 1024px; max-height:576px} #random_button {max-width: 100px !important}""" |
25 | 27 | elif res == 512: |
26 | 28 | resolution = '320_512' |
27 | | - css = """#input_img {max-width: 512px !important} #output_vid {max-width: 512px; max-height: 320px} #input_img2 {max-width: 512px !important} #output_vid {max-width: 512px; max-height: 320px}""" |
| 29 | + css = """#input_img {max-width: 512px !important} #output_vid {max-width: 512px; max-height: 320px} #random_button {max-width: 100px !important} #input_img2 {max-width: 512px !important} #output_vid {max-width: 512px; max-height: 320px}""" |
28 | 30 | elif res == 256: |
29 | 31 | resolution = '256_256' |
30 | | - css = """#input_img {max-width: 256px !important} #output_vid {max-width: 256px; max-height: 256px}""" |
| 32 | + css = """#input_img {max-width: 256px !important} #output_vid {max-width: 256px; max-height: 256px} #random_button {max-width: 100px !important}""" |
31 | 33 | else: |
32 | 34 | raise NotImplementedError(f"Unsupported resolution: {res}") |
33 | 35 | image2video = Image2Video(result_dir, resolution=resolution) |
@@ -55,12 +57,19 @@ def dynamicrafter_demo(result_dir='./tmp/', res=512): |
55 | 57 | with gr.Row(): |
56 | 58 | i2v_input_text = gr.Text(label='Prompts') |
57 | 59 | with gr.Row(): |
58 | | - i2v_seed = gr.Slider(label='Random Seed', minimum=0, maximum=50000, step=1, value=123) |
59 | 60 | i2v_eta = gr.Slider(minimum=0.0, maximum=1.0, step=0.1, label='ETA', value=1.0, elem_id="i2v_eta") |
60 | 61 | i2v_cfg_scale = gr.Slider(minimum=1.0, maximum=15.0, step=0.5, label='CFG Scale', value=7.5, elem_id="i2v_cfg_scale") |
61 | 62 | with gr.Row(): |
62 | 63 | i2v_steps = gr.Slider(minimum=1, maximum=60, step=1, elem_id="i2v_steps", label="Sampling steps", value=50) |
63 | 64 | i2v_motion = gr.Slider(minimum=5, maximum=30, step=1, elem_id="i2v_motion", label="FPS", value=10) |
| 65 | + with gr.Row(): |
| 66 | + i2v_seed = gr.Slider(label='Random Seed', minimum=0, maximum=max_seed, step=1, value=123) |
| 67 | + random_button = gr.Button('\U0001f3b2\ufe0f', elem_id="random_button") |
| 68 | + random_button.click( |
| 69 | + fn=lambda: random.randint(0, max_seed), |
| 70 | + outputs=i2v_seed, |
| 71 | + queue=False |
| 72 | + ) |
64 | 73 | i2v_end_btn = gr.Button("Generate") |
65 | 74 | with gr.Column(): |
66 | 75 | with gr.Row(): |
@@ -88,12 +97,19 @@ def dynamicrafter_demo(result_dir='./tmp/', res=512): |
88 | 97 | with gr.Row(): |
89 | 98 | i2v_input_text = gr.Text(label='Prompts') |
90 | 99 | with gr.Row(): |
91 | | - i2v_seed = gr.Slider(label='Random Seed', minimum=0, maximum=50000, step=1, value=123) |
92 | 100 | i2v_eta = gr.Slider(minimum=0.0, maximum=1.0, step=0.1, label='ETA', value=1.0, elem_id="i2v_eta") |
93 | 101 | i2v_cfg_scale = gr.Slider(minimum=1.0, maximum=15.0, step=0.5, label='CFG Scale', value=7.5, elem_id="i2v_cfg_scale") |
94 | 102 | with gr.Row(): |
95 | 103 | i2v_steps = gr.Slider(minimum=1, maximum=60, step=1, elem_id="i2v_steps", label="Sampling steps", value=50) |
96 | 104 | i2v_motion = gr.Slider(minimum=5, maximum=30, step=1, elem_id="i2v_motion", label="FPS", value=5) |
| 105 | + with gr.Row(): |
| 106 | + i2v_seed = gr.Slider(label='Random Seed', minimum=0, maximum=max_seed, step=1, value=123) |
| 107 | + random_button = gr.Button('\U0001f3b2\ufe0f', elem_id="random_button") |
| 108 | + random_button.click( |
| 109 | + fn=lambda: random.randint(0, max_seed), |
| 110 | + outputs=i2v_seed, |
| 111 | + queue=False |
| 112 | + ) |
97 | 113 | i2v_end_btn = gr.Button("Generate") |
98 | 114 | # with gr.Tab(label='Result'): |
99 | 115 | with gr.Row(): |
|
0 commit comments