-
Notifications
You must be signed in to change notification settings - Fork 0
/
cogvideox.py
executable file
·62 lines (48 loc) · 2.03 KB
/
cogvideox.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python3
from argparse import ArgumentParser, BooleanOptionalAction
from subprocess import call
from time import time
from diffusers import CogVideoXPipeline
from diffusers.utils import export_to_gif
from slugify import slugify
from torch import bfloat16
def main(arguments):
model = arguments.model
prompt = arguments.prompt
width = arguments.width
height = arguments.height
inference_steps = arguments.inference_steps
videos_per_batch = arguments.videos_per_batch
open_outputs = arguments.open_outputs
prompt = [prompt] * videos_per_batch
datatype = bfloat16
pipeline = CogVideoXPipeline.from_pretrained(model, torch_dtype=datatype)
pipeline.enable_model_cpu_offload()
pipeline.to(datatype)
videos = pipeline(
prompt=prompt,
guidance_scale=6,
num_inference_steps=inference_steps,
width=width,
height=height,
).frames
slugified_prompt = slugify(prompt[0])
slugified_model_name = slugify(model)
for video in videos:
try:
export_to_gif(video, f"outputs/{time()}-{slugified_model_name}-{width}-{height}-{slugified_prompt}.gif")
except OSError:
export_to_gif(video, f"outputs/{time()}-{slugified_model_name}-{width}-{height}.gif")
if open_outputs:
call(("open", "outputs"))
if __name__ == "__main__":
parser = ArgumentParser()
parser.add_argument("--model", default="THUDM/CogVideoX-5b", required=False)
parser.add_argument("--prompt", default="sunset in a remote valley in berner oberland", required=False)
parser.add_argument("--width", default=256, type=int, required=False)
parser.add_argument("--height", default=256, type=int, required=False)
parser.add_argument("--inference-steps", default=64, type=int, required=False)
parser.add_argument("--videos-per-batch", default=1, type=int, required=False)
parser.add_argument("--open-outputs", default=True, action=BooleanOptionalAction, required=False)
arguments = parser.parse_args()
main(arguments)