Spaces:
Running
Running
File size: 830 Bytes
280b1ae eb0262e 280b1ae |
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 |
import gradio as gr
import torch
from diffusers import AnimateDiffPipeline
from PIL import Image
import tempfile
import os
pipe = AnimateDiffPipeline.from_pretrained(
"ByteDance/AnimateDiff-Lightning",
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32
)
pipe.to("cuda" if torch.cuda.is_available() else "cpu")
def generate_video(prompt):
frames = pipe(prompt).frames
with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as temp_video:
pipe.export_to_video(frames, temp_video.name)
return temp_video.name
demo = gr.Interface(
fn=generate_video,
inputs=gr.Textbox(label="Prompt"),
outputs=gr.Video(label="Generated Animation"),
title="AnimateDiff Demo",
description="Generate animations from text prompts using AnimateDiff."
)
demo.launch()
|