Spaces:
Running on Zero
Running on Zero
Upload 3 files
Browse files- README.md +54 -8
- app.py +95 -0
- requirements.txt +9 -0
README.md
CHANGED
|
@@ -1,14 +1,60 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
-
python_version: '3.12'
|
| 9 |
app_file: app.py
|
| 10 |
pinned: false
|
| 11 |
-
short_description: Create vids
|
| 12 |
---
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: LTX Video Generator
|
| 3 |
+
emoji: 🎬
|
| 4 |
+
colorFrom: purple
|
| 5 |
+
colorTo: pink
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 5.0.1
|
|
|
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
+
# LTX Video Generator (Personal Use)
|
| 13 |
+
|
| 14 |
+
A free text-to-video generator built on [LTX-Video](https://huggingface.co/Lightricks/LTX-Video),
|
| 15 |
+
running as a Hugging Face Space with a Gradio UI.
|
| 16 |
+
|
| 17 |
+
## Deploy steps
|
| 18 |
+
|
| 19 |
+
1. Go to https://huggingface.co/new-space
|
| 20 |
+
2. Fill in:
|
| 21 |
+
- **Space name**: e.g. `my-ltx-video-generator`
|
| 22 |
+
- **SDK**: Gradio
|
| 23 |
+
- **Hardware**:
|
| 24 |
+
- Free CPU works but will be very slow (many minutes per clip).
|
| 25 |
+
- **ZeroGPU** is free if your account is eligible — best option for personal use.
|
| 26 |
+
- Or pick a paid GPU tier (e.g. T4/A10G) billed by the minute if you want faster, always-on generation.
|
| 27 |
+
- **Visibility**: Private (recommended, since this is personal use) or Public.
|
| 28 |
+
3. Once the Space is created, upload these three files (or push via git — see below):
|
| 29 |
+
- `app.py`
|
| 30 |
+
- `requirements.txt`
|
| 31 |
+
- `README.md`
|
| 32 |
+
4. The Space will build automatically. First build takes a while — it has to
|
| 33 |
+
download the LTX-Video model weights (several GB).
|
| 34 |
+
5. Once it says "Running", open the app and generate your first clip.
|
| 35 |
+
|
| 36 |
+
## Uploading via git (alternative to the web UI)
|
| 37 |
+
|
| 38 |
+
```bash
|
| 39 |
+
git clone https://huggingface.co/spaces/YOUR_USERNAME/my-ltx-video-generator
|
| 40 |
+
cd my-ltx-video-generator
|
| 41 |
+
# copy in app.py, requirements.txt, README.md
|
| 42 |
+
git add .
|
| 43 |
+
git commit -m "Initial LTX video generator"
|
| 44 |
+
git push
|
| 45 |
+
```
|
| 46 |
+
|
| 47 |
+
You'll need a Hugging Face **access token** (with "write" scope) to push:
|
| 48 |
+
Settings → Access Tokens → New token, then use it as your password when git
|
| 49 |
+
prompts for credentials (username = your HF username).
|
| 50 |
+
|
| 51 |
+
## Notes
|
| 52 |
+
|
| 53 |
+
- LTX-Video is gated/openly licensed under its own model license — the first
|
| 54 |
+
time the Space downloads it, you may need to have accepted the license on
|
| 55 |
+
the [model page](https://huggingface.co/Lightricks/LTX-Video) with the same
|
| 56 |
+
account that owns the Space.
|
| 57 |
+
- Generation settings (resolution, frame count, steps) are exposed in the UI
|
| 58 |
+
so you can trade off speed vs. quality.
|
| 59 |
+
- This is set up for personal/private use — keep the Space private if you
|
| 60 |
+
don't want to share generations publicly.
|
app.py
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import spaces
|
| 2 |
+
import torch
|
| 3 |
+
import gradio as gr
|
| 4 |
+
from diffusers import LTXPipeline
|
| 5 |
+
from diffusers.utils import export_to_video
|
| 6 |
+
|
| 7 |
+
MODEL_ID = "Lightricks/LTX-Video"
|
| 8 |
+
|
| 9 |
+
# Load once at startup. On a GPU Space this lands on CUDA; on a ZeroGPU
|
| 10 |
+
# Space, the @spaces.GPU decorator below handles moving things to GPU
|
| 11 |
+
# only while a request is running.
|
| 12 |
+
pipe = LTXPipeline.from_pretrained(MODEL_ID, torch_dtype=torch.bfloat16)
|
| 13 |
+
pipe.to("cuda") if torch.cuda.is_available() else None
|
| 14 |
+
|
| 15 |
+
DEFAULT_NEGATIVE = (
|
| 16 |
+
"worst quality, inconsistent motion, blurry, jittery, distorted, "
|
| 17 |
+
"low resolution, deformed"
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
@spaces.GPU(duration=120) # ignored/no-op on non-ZeroGPU hardware
|
| 22 |
+
def generate(prompt, negative_prompt, width, height, num_frames, steps, guidance, seed):
|
| 23 |
+
if not prompt or not prompt.strip():
|
| 24 |
+
raise gr.Error("Please enter a prompt describing the video you want.")
|
| 25 |
+
|
| 26 |
+
generator = None
|
| 27 |
+
if seed is not None and int(seed) >= 0:
|
| 28 |
+
generator = torch.Generator(device="cuda" if torch.cuda.is_available() else "cpu")
|
| 29 |
+
generator.manual_seed(int(seed))
|
| 30 |
+
|
| 31 |
+
video = pipe(
|
| 32 |
+
prompt=prompt,
|
| 33 |
+
negative_prompt=negative_prompt or DEFAULT_NEGATIVE,
|
| 34 |
+
width=int(width),
|
| 35 |
+
height=int(height),
|
| 36 |
+
num_frames=int(num_frames),
|
| 37 |
+
num_inference_steps=int(steps),
|
| 38 |
+
guidance_scale=float(guidance),
|
| 39 |
+
generator=generator,
|
| 40 |
+
).frames[0]
|
| 41 |
+
|
| 42 |
+
out_path = "/tmp/output.mp4"
|
| 43 |
+
export_to_video(video, out_path, fps=24)
|
| 44 |
+
return out_path
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
with gr.Blocks(title="Free LTX Video Generator") as demo:
|
| 48 |
+
gr.Markdown(
|
| 49 |
+
"""
|
| 50 |
+
# 🎬 LTX Video Generator
|
| 51 |
+
Personal text-to-video generator powered by [LTX-Video](https://huggingface.co/Lightricks/LTX-Video).
|
| 52 |
+
Describe a scene and generate a short clip.
|
| 53 |
+
"""
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
with gr.Row():
|
| 57 |
+
with gr.Column(scale=1):
|
| 58 |
+
prompt = gr.Textbox(
|
| 59 |
+
label="Prompt",
|
| 60 |
+
placeholder="A golden retriever running through a field of sunflowers at sunset, cinematic lighting",
|
| 61 |
+
lines=4,
|
| 62 |
+
)
|
| 63 |
+
negative_prompt = gr.Textbox(
|
| 64 |
+
label="Negative prompt (optional)",
|
| 65 |
+
value=DEFAULT_NEGATIVE,
|
| 66 |
+
lines=2,
|
| 67 |
+
)
|
| 68 |
+
with gr.Row():
|
| 69 |
+
width = gr.Slider(256, 1280, value=704, step=32, label="Width")
|
| 70 |
+
height = gr.Slider(256, 1280, value=480, step=32, label="Height")
|
| 71 |
+
with gr.Row():
|
| 72 |
+
num_frames = gr.Slider(9, 161, value=65, step=8, label="Number of frames")
|
| 73 |
+
steps = gr.Slider(10, 50, value=30, step=1, label="Inference steps")
|
| 74 |
+
with gr.Row():
|
| 75 |
+
guidance = gr.Slider(1.0, 10.0, value=3.0, step=0.1, label="Guidance scale")
|
| 76 |
+
seed = gr.Number(value=-1, label="Seed (-1 = random)")
|
| 77 |
+
run_btn = gr.Button("Generate Video", variant="primary")
|
| 78 |
+
|
| 79 |
+
with gr.Column(scale=1):
|
| 80 |
+
output_video = gr.Video(label="Result")
|
| 81 |
+
|
| 82 |
+
run_btn.click(
|
| 83 |
+
fn=generate,
|
| 84 |
+
inputs=[prompt, negative_prompt, width, height, num_frames, steps, guidance, seed],
|
| 85 |
+
outputs=output_video,
|
| 86 |
+
)
|
| 87 |
+
|
| 88 |
+
gr.Markdown(
|
| 89 |
+
"Tip: keep width/height multiples of 32 and frames as `8n+1` "
|
| 90 |
+
"(e.g. 65, 97, 121) — these match LTX-Video's training constraints "
|
| 91 |
+
"and avoid shape errors."
|
| 92 |
+
)
|
| 93 |
+
|
| 94 |
+
if __name__ == "__main__":
|
| 95 |
+
demo.queue(max_size=10).launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
git+https://github.com/huggingface/diffusers.git
|
| 2 |
+
transformers>=4.44.0
|
| 3 |
+
accelerate>=0.33.0
|
| 4 |
+
sentencepiece
|
| 5 |
+
imageio
|
| 6 |
+
imageio-ffmpeg
|
| 7 |
+
torch
|
| 8 |
+
spaces
|
| 9 |
+
gradio
|