File size: 1,460 Bytes
64e3117
b188cd2
 
 
5909022
b188cd2
 
 
 
 
1a5644f
 
b188cd2
 
 
5909022
 
 
64e3117
 
 
 
1a5644f
 
 
 
 
 
 
b188cd2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import yaml
import torch
import gradio as gr
from diffusers import StableVideoDiffusionPipeline, DiffusionPipeline

# Load configuration
with open("config.yaml") as f:
    cfg = yaml.safe_load(f)

# Retrieve your HF token from secrets/env
token = os.getenv("HF_TOKEN")

# Instantiate the correct pipeline based on model_id
def get_pipeline(model_id: str):
    if "animate" in model_id.lower():
        # Generic pipeline for animate-diffusion models
        return DiffusionPipeline.from_pretrained(
            model_id,
            torch_dtype=torch.float16,
            token=token
        ).to("cuda")
    # Stable video pipeline (fp16 revision)
    return StableVideoDiffusionPipeline.from_pretrained(
        model_id,
        torch_dtype=torch.float16,
        revision="fp16",
        token=token
    ).to("cuda")

# Initialize pipeline once
pipe = get_pipeline(cfg["model_id"])

# Generation function for Gradio
def generate(prompt: str):
    video = pipe(
        prompt,
        num_frames=cfg["num_frames"],
        height=cfg["height"],
        width=cfg["width"]
    ).videos[0]
    output_path = "output.mp4"
    video.save(output_path)
    return output_path

# Gradio interface setup
demo = gr.Interface(
    fn=generate,
    inputs=gr.Textbox(placeholder="Enter prompt…"),
    outputs="video",
    title="Text-to-Video",
    description="Configurable video generation via HF Spaces"
)

if __name__ == "__main__":
    demo.launch()