Spaces:
Paused
Paused
Nova AI CI commited on
Commit ยท
c0c2d3c
1
Parent(s): d823cb3
Deploy from Ttbik CI (cf314eeffe205ea90737c6f982318254d8e54676)
Browse files- app.py +98 -0
- requirements.txt +9 -0
app.py
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Owner spec, 2026-09-12 ("ุงุจุญุซ ุญุชู ูู ุงุถุทุฑุฑุช ูุชุบููุฑ ุงููู
ูุฐุฌ... ุญู ููุงุฆู
|
| 3 |
+
ูุฏุงุฆู
ูููุฏูู"): self-hosted real video generation on Hugging Face's
|
| 4 |
+
free "ZeroGPU" hardware tier โ see ai-system/app/hf_video.py's module
|
| 5 |
+
docstring for the full reasoning (why this exists, what it's tried
|
| 6 |
+
against, and the one honestly-unverified part: whether server-to-server
|
| 7 |
+
API calls from Render reliably get real GPU time the same way a human
|
| 8 |
+
visitor browsing this Space's own page does).
|
| 9 |
+
|
| 10 |
+
LTX-Video-2B (Lightricks, Apache 2.0 โ a real permissive license, no
|
| 11 |
+
conflict with reselling Nova as a paid product) chosen specifically
|
| 12 |
+
because it is the first DiT-based video model built for real-time
|
| 13 |
+
generation, a genuine speed advantage that matters here: ZeroGPU caps
|
| 14 |
+
every @spaces.GPU call at roughly ~120 real seconds regardless of plan
|
| 15 |
+
(not a guessed number โ real forum/doc reports, see hf_video.py).
|
| 16 |
+
Defaults below (short duration, reduced resolution/steps vs. the
|
| 17 |
+
model's own "full quality" example configuration) deliberately trade
|
| 18 |
+
some quality for a real, measured chance of finishing inside that
|
| 19 |
+
ceiling โ tune upward only after checking this Space's own real
|
| 20 |
+
per-call timing logs, not by guessing.
|
| 21 |
+
|
| 22 |
+
Deployed here via the same git-push CI pattern already used for
|
| 23 |
+
ModelScope Studio (see .github/workflows/deploy-hf-video-space.yml and
|
| 24 |
+
deploy-modelscope-studio.yml for the sibling workflow this one
|
| 25 |
+
mirrors) โ one-time manual setup still required: create the Space
|
| 26 |
+
itself on huggingface.co (SDK: Gradio, Hardware: ZeroGPU) before CI can
|
| 27 |
+
push code into it.
|
| 28 |
+
"""
|
| 29 |
+
import os
|
| 30 |
+
import tempfile
|
| 31 |
+
|
| 32 |
+
import gradio as gr
|
| 33 |
+
import spaces
|
| 34 |
+
import torch
|
| 35 |
+
from diffusers import LTXPipeline
|
| 36 |
+
from diffusers.utils import export_to_video
|
| 37 |
+
|
| 38 |
+
_MODEL_ID = "Lightricks/LTX-Video"
|
| 39 |
+
_FPS = 24
|
| 40 |
+
# Real ZeroGPU per-call ceiling (~120s, see this module's own docstring
|
| 41 |
+
# above) is the actual constraint here, not the model's own maximum
|
| 42 |
+
# supported duration โ kept short and conservative until real timing
|
| 43 |
+
# from this Space's own logs justifies raising it.
|
| 44 |
+
_MAX_SECONDS = 6
|
| 45 |
+
|
| 46 |
+
pipe = LTXPipeline.from_pretrained(_MODEL_ID, torch_dtype=torch.bfloat16)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def _seconds_to_frames(seconds: float) -> int:
|
| 50 |
+
"""LTX's temporal VAE compresses frames in groups of 8 โ the model
|
| 51 |
+
card's own full-quality example uses a frame count of the form
|
| 52 |
+
8n+1 (161 = 8*20+1) for exactly this reason. Rounds the requested
|
| 53 |
+
duration to the nearest valid 8n+1 count instead of an arbitrary
|
| 54 |
+
frame number the model was never validated against โ same real
|
| 55 |
+
architectural-constraint reasoning council.py's
|
| 56 |
+
_seconds_to_cogvideox_frames already uses for CogVideoX's own (4n+1)
|
| 57 |
+
constraint elsewhere in this project."""
|
| 58 |
+
seconds = max(1, min(seconds, _MAX_SECONDS))
|
| 59 |
+
raw_frames = round(seconds * _FPS)
|
| 60 |
+
n = round((raw_frames - 1) / 8)
|
| 61 |
+
return max(9, n * 8 + 1)
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
@spaces.GPU(duration=100)
|
| 65 |
+
def generate(prompt: str, seconds: float = 6) -> str:
|
| 66 |
+
"""The one real GPU-touching function in this file โ ZeroGPU only
|
| 67 |
+
grants actual CUDA access for the duration of this call; the rest
|
| 68 |
+
of this process runs CPU-only, which is why pipe.to("cuda") lives
|
| 69 |
+
inside here rather than at module load time."""
|
| 70 |
+
pipe.to("cuda")
|
| 71 |
+
num_frames = _seconds_to_frames(seconds)
|
| 72 |
+
video = pipe(
|
| 73 |
+
prompt=prompt,
|
| 74 |
+
negative_prompt="worst quality, blurry, distorted, deformed, static",
|
| 75 |
+
width=512,
|
| 76 |
+
height=320,
|
| 77 |
+
num_frames=num_frames,
|
| 78 |
+
num_inference_steps=20,
|
| 79 |
+
generator=torch.Generator(device="cuda").manual_seed(0),
|
| 80 |
+
).frames[0]
|
| 81 |
+
out_path = os.path.join(tempfile.mkdtemp(), "output.mp4")
|
| 82 |
+
export_to_video(video, out_path, fps=_FPS)
|
| 83 |
+
return out_path
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
# api_name defaults to the function's own name ("generate") for a
|
| 87 |
+
# gr.Interface โ matches ai-system/app/hf_video.py's
|
| 88 |
+
# client.predict(..., api_name="/generate") exactly, no explicit
|
| 89 |
+
# override needed.
|
| 90 |
+
demo = gr.Interface(
|
| 91 |
+
fn=generate,
|
| 92 |
+
inputs=[gr.Textbox(label="prompt"), gr.Number(label="seconds", value=6)],
|
| 93 |
+
outputs=gr.Video(label="video"),
|
| 94 |
+
title="Nova AI โ Real Video (LTX-Video-2B, ZeroGPU)",
|
| 95 |
+
)
|
| 96 |
+
|
| 97 |
+
if __name__ == "__main__":
|
| 98 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch
|
| 2 |
+
diffusers
|
| 3 |
+
transformers
|
| 4 |
+
accelerate
|
| 5 |
+
sentencepiece
|
| 6 |
+
imageio
|
| 7 |
+
imageio-ffmpeg
|
| 8 |
+
spaces
|
| 9 |
+
gradio
|