Spaces:
Runtime error
Runtime error
Commit
•
5e93a43
1
Parent(s):
706f2ad
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import os
|
2 |
os.system("pip install torch")
|
3 |
os.system("pip install diffusers")
|
|
|
4 |
import torch
|
5 |
from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler
|
6 |
from diffusers.utils import export_to_video
|
@@ -20,4 +21,36 @@ gr.Interface(
|
|
20 |
inputs=gr.Textbox(label="어떤 비디오를 생성할까요? : "),
|
21 |
outputs=result
|
22 |
|
23 |
-
).launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
os.system("pip install torch")
|
3 |
os.system("pip install diffusers")
|
4 |
+
'''
|
5 |
import torch
|
6 |
from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler
|
7 |
from diffusers.utils import export_to_video
|
|
|
21 |
inputs=gr.Textbox(label="어떤 비디오를 생성할까요? : "),
|
22 |
outputs=result
|
23 |
|
24 |
+
).launch()'''
|
25 |
+
|
26 |
+
import torch
|
27 |
+
import imageio
|
28 |
+
from diffusers import TextToVideoZeroPipeline
|
29 |
+
import numpy as np
|
30 |
+
|
31 |
+
model_id = "runwayml/stable-diffusion-v1-5"
|
32 |
+
pipe = TextToVideoZeroPipeline.from_pretrained(model_id, torch_dtype=torch.float16).to("cuda")
|
33 |
+
seed = 0
|
34 |
+
video_length = 8
|
35 |
+
chunk_size = 4
|
36 |
+
prompt = "A panda is playing guitar on times square"
|
37 |
+
|
38 |
+
# Generate the video chunk-by-chunk
|
39 |
+
result = []
|
40 |
+
chunk_ids = np.arange(0, video_length, chunk_size - 1)
|
41 |
+
generator = torch.Generator(device="cuda")
|
42 |
+
for i in range(len(chunk_ids)):
|
43 |
+
print(f"Processing chunk {i + 1} / {len(chunk_ids)}")
|
44 |
+
ch_start = chunk_ids[i]
|
45 |
+
ch_end = video_length if i == len(chunk_ids) - 1 else chunk_ids[i + 1]
|
46 |
+
# Attach the first frame for Cross Frame Attention
|
47 |
+
frame_ids = [0] + list(range(ch_start, ch_end))
|
48 |
+
# Fix the seed for the temporal consistency
|
49 |
+
generator.manual_seed(seed)
|
50 |
+
output = pipe(prompt=prompt, video_length=len(frame_ids), generator=generator, frame_ids=frame_ids)
|
51 |
+
result.append(output.images[1:])
|
52 |
+
|
53 |
+
# Concatenate chunks and save
|
54 |
+
result = np.concatenate(result)
|
55 |
+
result = [(r * 255).astype("uint8") for r in result]
|
56 |
+
imageio.mimsave("video.mp4", result, fps=4)
|