Download app.py from OneClub/ttv: direct link, hf CLI and curl.
- Browser
- Download file 1.46 kB
-
https://huggingface.co/spaces/OneClub/ttv/resolve/main/app.py
- Command line
-
hf download hf://spaces/OneClub/ttv/app.py
-
curl -L -o app.py https://huggingface.co/spaces/OneClub/ttv/resolve/main/app.py
1.46 kB
| 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() |