Spaces:
Runtime error
Runtime error
Update frame_gen.py
Browse files- frame_gen.py +49 -0
frame_gen.py
CHANGED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from diffusers import AnimateDiffPipeline, DDIMScheduler, MotionAdapter
|
| 3 |
+
from diffusers.utils import export_to_gif
|
| 4 |
+
from moviepy.editor import VideoFileClip, concatenate_videoclips
|
| 5 |
+
|
| 6 |
+
adapter = MotionAdapter.from_pretrained("guoyww/animatediff-motion-adapter-v1-5-2", torch_dtype=torch.float16)
|
| 7 |
+
|
| 8 |
+
pipeline = AnimateDiffPipeline.from_pretrained("emilianJR/epiCRealism", motion_adapter=adapter, torch_dtype=torch.float16)
|
| 9 |
+
scheduler = DDIMScheduler.from_pretrained(
|
| 10 |
+
"emilianJR/epiCRealism",
|
| 11 |
+
subfolder="scheduler",
|
| 12 |
+
clip_sample=False,
|
| 13 |
+
timestep_spacing="linspace",
|
| 14 |
+
beta_schedule="linear",
|
| 15 |
+
steps_offset=1,
|
| 16 |
+
)
|
| 17 |
+
pipeline.scheduler = scheduler
|
| 18 |
+
pipeline.enable_vae_slicing()
|
| 19 |
+
pipeline.enable_model_cpu_offload()
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def gen_movie(frames_desc):
|
| 23 |
+
x = 1
|
| 24 |
+
for frame_description in frames_desc:
|
| 25 |
+
output = pipeline(
|
| 26 |
+
prompt="frame_description",
|
| 27 |
+
negative_prompt="high resolution",
|
| 28 |
+
num_frames=16,
|
| 29 |
+
guidance_scale=7.5,
|
| 30 |
+
num_inference_steps=50,
|
| 31 |
+
generator=torch.Generator("cpu").manual_seed(0),
|
| 32 |
+
)
|
| 33 |
+
frames = output.frames[0]
|
| 34 |
+
export_to_gif(frames, f'animation{x}.gif')
|
| 35 |
+
x++
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
# List to store VideoFileClip objects for each input GIF
|
| 39 |
+
video_clips = []
|
| 40 |
+
|
| 41 |
+
# Load each input GIF file and append it to the list
|
| 42 |
+
for x in range(1,11):
|
| 43 |
+
video_clips.append(VideoFileClip(f'animation{x}.gif'))
|
| 44 |
+
|
| 45 |
+
# Concatenate the video clips to create a single video
|
| 46 |
+
final_clip = concatenate_videoclips(video_clips)
|
| 47 |
+
|
| 48 |
+
# Export the final video to a new MP4 file
|
| 49 |
+
final_clip.write_videofile("combined_video.mp4", codec="libx264", fps=24)
|