Spaces:
Running
Running
Delete generate_video.py
Browse files- generate_video.py +0 -29
generate_video.py
DELETED
|
@@ -1,29 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
from diffusers import StableDiffusionPipeline
|
| 3 |
-
import torch
|
| 4 |
-
from moviepy.editor import ImageSequenceClip
|
| 5 |
-
from PIL import Image
|
| 6 |
-
from tqdm import tqdm
|
| 7 |
-
|
| 8 |
-
def generate_video_from_text(prompt, output_path="output.mp4", steps=30, fps=8):
|
| 9 |
-
pipe = StableDiffusionPipeline.from_pretrained(
|
| 10 |
-
"CompVis/stable-diffusion-v1-4",
|
| 11 |
-
torch_dtype=torch.float32
|
| 12 |
-
).to("cpu")
|
| 13 |
-
|
| 14 |
-
images = []
|
| 15 |
-
for i in tqdm(range(steps), desc="Generating frames"):
|
| 16 |
-
generator = torch.manual_seed(i + 100)
|
| 17 |
-
image = pipe(prompt, guidance_scale=7.5, generator=generator).images[0]
|
| 18 |
-
images.append(image)
|
| 19 |
-
|
| 20 |
-
os.makedirs("temp_frames", exist_ok=True)
|
| 21 |
-
frame_paths = []
|
| 22 |
-
for idx, img in enumerate(images):
|
| 23 |
-
path = f"temp_frames/frame_{idx:03d}.png"
|
| 24 |
-
img.save(path)
|
| 25 |
-
frame_paths.append(path)
|
| 26 |
-
|
| 27 |
-
clip = ImageSequenceClip(frame_paths, fps=fps)
|
| 28 |
-
clip.write_videofile(output_path, codec="libx264")
|
| 29 |
-
return output_path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|