Skip to content

Commit 463d1a0

Browse files
authored
Merge pull request Doubiiu#94 from dailingx/dev
Optimize some code
2 parents 59ef5a5 + ff9f5b9 commit 463d1a0

File tree

4 files changed

+58
-14
lines changed

4 files changed

+58
-14
lines changed

gradio_app.py

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os, argparse
22
import sys
33
import gradio as gr
4+
import random
45
from scripts.gradio.i2v_test import Image2Video
56
sys.path.insert(1, os.path.join(sys.path[0], 'lvdm'))
67

@@ -31,17 +32,19 @@
3132
['prompts/256/guitar0.jpeg', 'bear playing guitar happily, snowing', 50, 7.5, 1.0, 3, 122]
3233
]
3334

35+
max_seed = 2 ** 31
36+
3437

3538
def dynamicrafter_demo(result_dir='./tmp/', res=1024):
3639
if res == 1024:
3740
resolution = '576_1024'
38-
css = """#input_img {max-width: 1024px !important} #output_vid {max-width: 1024px; max-height:576px}"""
41+
css = """#input_img {max-width: 1024px !important} #output_vid {max-width: 1024px; max-height:576px} #random_button {max-width: 100px !important}"""
3942
elif res == 512:
4043
resolution = '320_512'
41-
css = """#input_img {max-width: 512px !important} #output_vid {max-width: 512px; max-height: 320px}"""
44+
css = """#input_img {max-width: 512px !important} #output_vid {max-width: 512px; max-height: 320px} #random_button {max-width: 100px !important}"""
4245
elif res == 256:
4346
resolution = '256_256'
44-
css = """#input_img {max-width: 256px !important} #output_vid {max-width: 256px; max-height: 256px}"""
47+
css = """#input_img {max-width: 256px !important} #output_vid {max-width: 256px; max-height: 256px} #random_button {max-width: 100px !important}"""
4548
else:
4649
raise NotImplementedError(f"Unsupported resolution: {res}")
4750
image2video = Image2Video(result_dir, resolution=resolution)
@@ -70,12 +73,19 @@ def dynamicrafter_demo(result_dir='./tmp/', res=1024):
7073
with gr.Row():
7174
i2v_input_text = gr.Text(label='Prompts')
7275
with gr.Row():
73-
i2v_seed = gr.Slider(label='Random Seed', minimum=0, maximum=10000, step=1, value=123)
7476
i2v_eta = gr.Slider(minimum=0.0, maximum=1.0, step=0.1, label='ETA', value=1.0, elem_id="i2v_eta")
7577
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")
7678
with gr.Row():
7779
i2v_steps = gr.Slider(minimum=1, maximum=60, step=1, elem_id="i2v_steps", label="Sampling steps", value=50)
7880
i2v_motion = gr.Slider(minimum=5, maximum=20, step=1, elem_id="i2v_motion", label="FPS", value=10)
81+
with gr.Row():
82+
i2v_seed = gr.Slider(label='Random Seed', minimum=0, maximum=max_seed, step=1, value=123)
83+
random_button = gr.Button('\U0001f3b2\ufe0f', elem_id="random_button")
84+
random_button.click(
85+
fn=lambda: random.randint(0, max_seed),
86+
outputs=i2v_seed,
87+
queue=False
88+
)
7989
i2v_end_btn = gr.Button("Generate")
8090
# with gr.Tab(label='Result'):
8191
with gr.Row():
@@ -101,12 +111,19 @@ def dynamicrafter_demo(result_dir='./tmp/', res=1024):
101111
with gr.Row():
102112
i2v_input_text = gr.Text(label='Prompts')
103113
with gr.Row():
104-
i2v_seed = gr.Slider(label='Random Seed', minimum=0, maximum=10000, step=1, value=123)
105114
i2v_eta = gr.Slider(minimum=0.0, maximum=1.0, step=0.1, label='ETA', value=1.0, elem_id="i2v_eta")
106115
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")
107116
with gr.Row():
108117
i2v_steps = gr.Slider(minimum=1, maximum=60, step=1, elem_id="i2v_steps", label="Sampling steps", value=50)
109118
i2v_motion = gr.Slider(minimum=15, maximum=30, step=1, elem_id="i2v_motion", label="FPS", value=24)
119+
with gr.Row():
120+
i2v_seed = gr.Slider(label='Random Seed', minimum=0, maximum=max_seed, step=1, value=123)
121+
random_button = gr.Button('\U0001f3b2\ufe0f', elem_id="random_button")
122+
random_button.click(
123+
fn=lambda: random.randint(0, max_seed),
124+
outputs=i2v_seed,
125+
queue=False
126+
)
110127
i2v_end_btn = gr.Button("Generate")
111128
# with gr.Tab(label='Result'):
112129
with gr.Row():
@@ -132,12 +149,19 @@ def dynamicrafter_demo(result_dir='./tmp/', res=1024):
132149
with gr.Row():
133150
i2v_input_text = gr.Text(label='Prompts')
134151
with gr.Row():
135-
i2v_seed = gr.Slider(label='Random Seed', minimum=0, maximum=10000, step=1, value=123)
136152
i2v_eta = gr.Slider(minimum=0.0, maximum=1.0, step=0.1, label='ETA', value=1.0, elem_id="i2v_eta")
137153
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")
138154
with gr.Row():
139155
i2v_steps = gr.Slider(minimum=1, maximum=60, step=1, elem_id="i2v_steps", label="Sampling steps", value=50)
140156
i2v_motion = gr.Slider(minimum=1, maximum=4, step=1, elem_id="i2v_motion", label="Motion magnitude", value=3)
157+
with gr.Row():
158+
i2v_seed = gr.Slider(label='Random Seed', minimum=0, maximum=max_seed, step=1, value=123)
159+
random_button = gr.Button('\U0001f3b2\ufe0f', elem_id="random_button")
160+
random_button.click(
161+
fn=lambda: random.randint(0, max_seed),
162+
outputs=i2v_seed,
163+
queue=False
164+
)
141165
i2v_end_btn = gr.Button("Generate")
142166
# with gr.Tab(label='Result'):
143167
with gr.Row():

gradio_app_interp_and_loop.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os, argparse
22
import sys
33
import gradio as gr
4+
import random
45
from scripts.gradio.i2v_test_application import Image2Video
56
sys.path.insert(1, os.path.join(sys.path[0], 'lvdm'))
67

@@ -16,18 +17,19 @@
1617
['prompts/512_loop/40.png', 'flowers swaying in the wind', 50, 7.5, 1.0, 5, 234],
1718
]
1819

20+
max_seed = 2 ** 31
1921

2022

2123
def dynamicrafter_demo(result_dir='./tmp/', res=512):
2224
if res == 1024:
2325
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}"""
2527
elif res == 512:
2628
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}"""
2830
elif res == 256:
2931
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}"""
3133
else:
3234
raise NotImplementedError(f"Unsupported resolution: {res}")
3335
image2video = Image2Video(result_dir, resolution=resolution)
@@ -55,12 +57,19 @@ def dynamicrafter_demo(result_dir='./tmp/', res=512):
5557
with gr.Row():
5658
i2v_input_text = gr.Text(label='Prompts')
5759
with gr.Row():
58-
i2v_seed = gr.Slider(label='Random Seed', minimum=0, maximum=50000, step=1, value=123)
5960
i2v_eta = gr.Slider(minimum=0.0, maximum=1.0, step=0.1, label='ETA', value=1.0, elem_id="i2v_eta")
6061
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")
6162
with gr.Row():
6263
i2v_steps = gr.Slider(minimum=1, maximum=60, step=1, elem_id="i2v_steps", label="Sampling steps", value=50)
6364
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+
)
6473
i2v_end_btn = gr.Button("Generate")
6574
with gr.Column():
6675
with gr.Row():
@@ -88,12 +97,19 @@ def dynamicrafter_demo(result_dir='./tmp/', res=512):
8897
with gr.Row():
8998
i2v_input_text = gr.Text(label='Prompts')
9099
with gr.Row():
91-
i2v_seed = gr.Slider(label='Random Seed', minimum=0, maximum=50000, step=1, value=123)
92100
i2v_eta = gr.Slider(minimum=0.0, maximum=1.0, step=0.1, label='ETA', value=1.0, elem_id="i2v_eta")
93101
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")
94102
with gr.Row():
95103
i2v_steps = gr.Slider(minimum=1, maximum=60, step=1, elem_id="i2v_steps", label="Sampling steps", value=50)
96104
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+
)
97113
i2v_end_btn = gr.Button("Generate")
98114
# with gr.Tab(label='Result'):
99115
with gr.Row():

lvdm/data/webvid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def __init__(self,
7070
self.spatial_transform = None
7171

7272
def _load_metadata(self):
73-
metadata = pd.read_csv(self.meta_path)
73+
metadata = pd.read_csv(self.meta_path, dtype=str)
7474
print(f'>>> {len(metadata)} data samples loaded.')
7575
if self.subsample is not None:
7676
metadata = metadata.sample(self.subsample, random_state=0)

scripts/evaluation/inference.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from lvdm.models.samplers.ddim import DDIMSampler
1515
from lvdm.models.samplers.ddim_multiplecond import DDIMSampler as DDIMSampler_multicond
1616
from utils.utils import instantiate_from_config
17+
import random
1718

1819

1920
def get_filelist(data_dir, postfixes):
@@ -351,7 +352,10 @@ def get_parser():
351352
print("@DynamiCrafter cond-Inference: %s"%now)
352353
parser = get_parser()
353354
args = parser.parse_args()
354-
355-
seed_everything(args.seed)
355+
356+
seed = args.seed
357+
if seed < 0:
358+
seed = random.randint(0, 2 ** 31)
359+
seed_everything(seed)
356360
rank, gpu_num = 0, 1
357361
run_inference(args, gpu_num, rank)

0 commit comments

Comments
 (0)