Spaces:
Running on Zero
Running on Zero
Fix sth
#3
by
BestWishYsh - opened
app.py
CHANGED
|
@@ -1,43 +1,13 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import subprocess
|
| 3 |
-
import sys
|
| 4 |
-
import time
|
| 5 |
import tempfile
|
| 6 |
-
import
|
| 7 |
-
import torch
|
| 8 |
-
|
| 9 |
-
# ---------------------------------------------------------------------------
|
| 10 |
-
# Install private diffusers fork
|
| 11 |
-
# ---------------------------------------------------------------------------
|
| 12 |
-
_APP_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 13 |
-
ZIP_PATH = os.path.join(_APP_DIR, "helios_diffusers.zip")
|
| 14 |
-
EXTRACT_DIR = os.path.join(_APP_DIR, "_helios_diffusers")
|
| 15 |
-
_PKG_ROOT = os.path.join(EXTRACT_DIR, "diffusers-new-model-addition-helios-helios")
|
| 16 |
-
|
| 17 |
-
if not os.path.isdir(_PKG_ROOT):
|
| 18 |
-
print(f"[setup] Extracting {ZIP_PATH}")
|
| 19 |
-
with zipfile.ZipFile(ZIP_PATH, "r") as zf:
|
| 20 |
-
zf.extractall(EXTRACT_DIR)
|
| 21 |
-
|
| 22 |
-
print(f"[setup] Installing diffusers from {_PKG_ROOT}")
|
| 23 |
-
try:
|
| 24 |
-
subprocess.check_call([sys.executable, "-m", "pip", "install", _PKG_ROOT])
|
| 25 |
-
except subprocess.CalledProcessError as e:
|
| 26 |
-
print(f"[setup] pip install failed (exit {e.returncode}), falling back to sys.path")
|
| 27 |
-
|
| 28 |
-
_SRC_DIR = os.path.join(_PKG_ROOT, "src")
|
| 29 |
-
if os.path.isdir(_SRC_DIR):
|
| 30 |
-
sys.path.insert(0, _SRC_DIR)
|
| 31 |
|
| 32 |
import gradio as gr
|
| 33 |
import spaces
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
HeliosDMDScheduler
|
| 38 |
-
)
|
| 39 |
from diffusers.utils import export_to_video, load_image, load_video
|
| 40 |
-
|
| 41 |
|
| 42 |
# ---------------------------------------------------------------------------
|
| 43 |
# Pre-load model
|
|
@@ -47,18 +17,30 @@ MODEL_ID = "BestWishYsh/Helios-Distilled"
|
|
| 47 |
vae = AutoencoderKLWan.from_pretrained(MODEL_ID, subfolder="vae", torch_dtype=torch.float32)
|
| 48 |
scheduler = HeliosDMDScheduler.from_pretrained(MODEL_ID, subfolder="scheduler")
|
| 49 |
pipe = HeliosPyramidPipeline.from_pretrained(
|
| 50 |
-
MODEL_ID,
|
| 51 |
-
vae=vae,
|
| 52 |
-
scheduler=scheduler,
|
| 53 |
-
torch_dtype=torch.bfloat16,
|
| 54 |
-
is_distilled=True
|
| 55 |
)
|
| 56 |
|
| 57 |
-
# aoti_load_(pipe.transformer, "multimodalart/helios-distilled-transformer", "helios_distilled_transformer.pt2")
|
| 58 |
-
|
| 59 |
pipe.to("cuda")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
-
pipe.transformer.set_attention_backend("_flash_3_hub")
|
| 62 |
|
| 63 |
# ---------------------------------------------------------------------------
|
| 64 |
# Generation
|
|
@@ -113,6 +95,7 @@ def generate_video(
|
|
| 113 |
info = f"Generated in {elapsed:.1f}s · {num_frames} frames · {height}×{width}"
|
| 114 |
return tmp.name, info
|
| 115 |
|
|
|
|
| 116 |
# ---------------------------------------------------------------------------
|
| 117 |
# UI Setup
|
| 118 |
# ---------------------------------------------------------------------------
|
|
@@ -124,17 +107,44 @@ def update_conditional_visibility(mode):
|
|
| 124 |
else:
|
| 125 |
return gr.update(visible=False), gr.update(visible=False)
|
| 126 |
|
|
|
|
| 127 |
CSS = """
|
| 128 |
-
#header { text-align: center; margin-bottom:
|
| 129 |
-
#header h1 { font-size: 2.2em; margin-bottom: 0; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
.contain { max-width: 1350px; margin: 0 auto !important; }
|
| 131 |
"""
|
| 132 |
|
| 133 |
-
with gr.Blocks(
|
| 134 |
gr.HTML(
|
| 135 |
"""
|
|
|
|
|
|
|
|
|
|
| 136 |
<div id="header">
|
| 137 |
-
<h1>🎬 Helios 14B
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
</div>
|
| 139 |
"""
|
| 140 |
)
|
|
@@ -161,7 +171,7 @@ with gr.Blocks(css=CSS, title="Helios Video Generation", theme=gr.themes.Soft())
|
|
| 161 |
"of hard and soft corals in shades of red, orange, and green. The photo captures "
|
| 162 |
"the fish from a slightly elevated angle, emphasizing its lively movements and the "
|
| 163 |
"vivid colors of its surroundings. A close-up shot with dynamic movement."
|
| 164 |
-
)
|
| 165 |
)
|
| 166 |
with gr.Accordion("Advanced Settings", open=False):
|
| 167 |
with gr.Row():
|
|
@@ -183,7 +193,18 @@ with gr.Blocks(css=CSS, title="Helios Video Generation", theme=gr.themes.Soft())
|
|
| 183 |
mode.change(fn=update_conditional_visibility, inputs=[mode], outputs=[image_input, video_input])
|
| 184 |
generate_btn.click(
|
| 185 |
fn=generate_video,
|
| 186 |
-
inputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
outputs=[video_output, info_output],
|
| 188 |
)
|
| 189 |
|
|
@@ -200,6 +221,8 @@ with gr.Blocks(css=CSS, title="Helios Video Generation", theme=gr.themes.Soft())
|
|
| 200 |
"of hard and soft corals in shades of red, orange, and green. The photo captures "
|
| 201 |
"the fish from a slightly elevated angle, emphasizing its lively movements and the "
|
| 202 |
"vivid colors of its surroundings. A close-up shot with dynamic movement.",
|
|
|
|
|
|
|
| 203 |
],
|
| 204 |
[
|
| 205 |
"Text-to-Video",
|
|
@@ -211,6 +234,8 @@ with gr.Blocks(css=CSS, title="Helios Video Generation", theme=gr.themes.Soft())
|
|
| 211 |
"smile as if he found the answer to the mystery of life, the lighting is very cinematic "
|
| 212 |
"with the golden light and the Parisian streets and city in the background, depth of "
|
| 213 |
"field, cinematic 35mm film.",
|
|
|
|
|
|
|
| 214 |
],
|
| 215 |
[
|
| 216 |
"Text-to-Video",
|
|
@@ -221,11 +246,25 @@ with gr.Blocks(css=CSS, title="Helios Video Generation", theme=gr.themes.Soft())
|
|
| 221 |
"of the Amalfi Coast Italy, several distant people are seen walking and enjoying vistas "
|
| 222 |
"on patios of the dramatic ocean views, the warm glow of the afternoon sun creates a "
|
| 223 |
"magical and romantic feeling to the scene, the view is stunning captured with beautiful photography.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
],
|
| 225 |
],
|
| 226 |
-
inputs=[mode, prompt],
|
| 227 |
label="Example Prompts",
|
| 228 |
)
|
| 229 |
|
| 230 |
if __name__ == "__main__":
|
| 231 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import tempfile
|
| 2 |
+
import time
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
import gradio as gr
|
| 5 |
import spaces
|
| 6 |
+
import torch
|
| 7 |
+
|
| 8 |
+
from diffusers import AutoencoderKLWan, HeliosDMDScheduler, HeliosPyramidPipeline
|
|
|
|
|
|
|
| 9 |
from diffusers.utils import export_to_video, load_image, load_video
|
| 10 |
+
|
| 11 |
|
| 12 |
# ---------------------------------------------------------------------------
|
| 13 |
# Pre-load model
|
|
|
|
| 17 |
vae = AutoencoderKLWan.from_pretrained(MODEL_ID, subfolder="vae", torch_dtype=torch.float32)
|
| 18 |
scheduler = HeliosDMDScheduler.from_pretrained(MODEL_ID, subfolder="scheduler")
|
| 19 |
pipe = HeliosPyramidPipeline.from_pretrained(
|
| 20 |
+
MODEL_ID, vae=vae, scheduler=scheduler, torch_dtype=torch.bfloat16, is_distilled=True
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
)
|
| 22 |
|
|
|
|
|
|
|
| 23 |
pipe.to("cuda")
|
| 24 |
+
try:
|
| 25 |
+
pipe.transformer.set_attention_backend("_flash_3_hub")
|
| 26 |
+
except Exception:
|
| 27 |
+
pipe.transformer.set_attention_backend("flash_hub")
|
| 28 |
+
|
| 29 |
+
# @spaces.GPU(duration=1500)
|
| 30 |
+
# def compile_transformer():
|
| 31 |
+
# with spaces.aoti_capture(pipe.transformer) as call:
|
| 32 |
+
# pipe("arbitrary example prompt")
|
| 33 |
+
|
| 34 |
+
# exported = torch.export.export(
|
| 35 |
+
# pipe.transformer,
|
| 36 |
+
# args=call.args,
|
| 37 |
+
# kwargs=call.kwargs,
|
| 38 |
+
# )
|
| 39 |
+
# return spaces.aoti_compile(exported)
|
| 40 |
+
|
| 41 |
+
# compiled_transformer = compile_transformer()
|
| 42 |
+
# spaces.aoti_apply(compiled_transformer, pipe.transformer)
|
| 43 |
|
|
|
|
| 44 |
|
| 45 |
# ---------------------------------------------------------------------------
|
| 46 |
# Generation
|
|
|
|
| 95 |
info = f"Generated in {elapsed:.1f}s · {num_frames} frames · {height}×{width}"
|
| 96 |
return tmp.name, info
|
| 97 |
|
| 98 |
+
|
| 99 |
# ---------------------------------------------------------------------------
|
| 100 |
# UI Setup
|
| 101 |
# ---------------------------------------------------------------------------
|
|
|
|
| 107 |
else:
|
| 108 |
return gr.update(visible=False), gr.update(visible=False)
|
| 109 |
|
| 110 |
+
|
| 111 |
CSS = """
|
| 112 |
+
#header { text-align: center; margin-bottom: 1.5em; }
|
| 113 |
+
#header h1 { font-size: 2.2em; margin-bottom: 0.2em; }
|
| 114 |
+
.logo { max-height: 100px; margin: 0 auto 10px auto; display: block; }
|
| 115 |
+
.link-buttons { display: flex; justify-content: center; gap: 15px; margin-top: 10px; }
|
| 116 |
+
.link-buttons a {
|
| 117 |
+
background-color: #2b3137;
|
| 118 |
+
color: #ffffff !important;
|
| 119 |
+
padding: 8px 20px;
|
| 120 |
+
border-radius: 6px;
|
| 121 |
+
text-decoration: none;
|
| 122 |
+
font-weight: 600;
|
| 123 |
+
font-size: 1em;
|
| 124 |
+
transition: all 0.2s ease-in-out;
|
| 125 |
+
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
| 126 |
+
}
|
| 127 |
+
.link-buttons a:hover { background-color: #4a535c; transform: translateY(-1px); }
|
| 128 |
.contain { max-width: 1350px; margin: 0 auto !important; }
|
| 129 |
"""
|
| 130 |
|
| 131 |
+
with gr.Blocks(title="Helios Video Generation") as demo:
|
| 132 |
gr.HTML(
|
| 133 |
"""
|
| 134 |
+
<div style='display: flex; align-items: center; justify-content: center; width: 100%;'>
|
| 135 |
+
<img src="https://github.com/PKU-YuanGroup/Helios-Page/blob/main/figures/logo_white.png?raw=true" style='width: 400px; height: auto;' />
|
| 136 |
+
</div>
|
| 137 |
<div id="header">
|
| 138 |
+
<h1>🎬 Helios 14B Distilled: Real Real-Time Long Video Generation Model</h1>
|
| 139 |
+
<p style="font-size: 1.1em; color: #666; margin-top: 0.5em; margin-bottom: 1em;">
|
| 140 |
+
If you like our project, please give us a star ⭐ on GitHub for the latest update.
|
| 141 |
+
</p>
|
| 142 |
+
<div class="link-buttons">
|
| 143 |
+
<a href="https://github.com/PKU-YuanGroup/Helios" target="_blank">💻 Code</a>
|
| 144 |
+
<a href="https://pku-yuangroup.github.io/Helios-Page" target="_blank">📄 Page</a>
|
| 145 |
+
<a href="https://www.youtube.com/watch?v=vd_AgHtOUFQ" target="_blank">🎥 Main Feature</a>
|
| 146 |
+
<a href="https://www.youtube.com/watch?v=1GeIU2Dn7UY" target="_blank">⚡ Inference Speed</a>
|
| 147 |
+
</div>
|
| 148 |
</div>
|
| 149 |
"""
|
| 150 |
)
|
|
|
|
| 171 |
"of hard and soft corals in shades of red, orange, and green. The photo captures "
|
| 172 |
"the fish from a slightly elevated angle, emphasizing its lively movements and the "
|
| 173 |
"vivid colors of its surroundings. A close-up shot with dynamic movement."
|
| 174 |
+
),
|
| 175 |
)
|
| 176 |
with gr.Accordion("Advanced Settings", open=False):
|
| 177 |
with gr.Row():
|
|
|
|
| 193 |
mode.change(fn=update_conditional_visibility, inputs=[mode], outputs=[image_input, video_input])
|
| 194 |
generate_btn.click(
|
| 195 |
fn=generate_video,
|
| 196 |
+
inputs=[
|
| 197 |
+
mode,
|
| 198 |
+
prompt,
|
| 199 |
+
image_input,
|
| 200 |
+
video_input,
|
| 201 |
+
height,
|
| 202 |
+
width,
|
| 203 |
+
num_frames,
|
| 204 |
+
num_inference_steps,
|
| 205 |
+
seed,
|
| 206 |
+
is_amplify_first_chunk,
|
| 207 |
+
],
|
| 208 |
outputs=[video_output, info_output],
|
| 209 |
)
|
| 210 |
|
|
|
|
| 221 |
"of hard and soft corals in shades of red, orange, and green. The photo captures "
|
| 222 |
"the fish from a slightly elevated angle, emphasizing its lively movements and the "
|
| 223 |
"vivid colors of its surroundings. A close-up shot with dynamic movement.",
|
| 224 |
+
None,
|
| 225 |
+
None,
|
| 226 |
],
|
| 227 |
[
|
| 228 |
"Text-to-Video",
|
|
|
|
| 234 |
"smile as if he found the answer to the mystery of life, the lighting is very cinematic "
|
| 235 |
"with the golden light and the Parisian streets and city in the background, depth of "
|
| 236 |
"field, cinematic 35mm film.",
|
| 237 |
+
None,
|
| 238 |
+
None,
|
| 239 |
],
|
| 240 |
[
|
| 241 |
"Text-to-Video",
|
|
|
|
| 246 |
"of the Amalfi Coast Italy, several distant people are seen walking and enjoying vistas "
|
| 247 |
"on patios of the dramatic ocean views, the warm glow of the afternoon sun creates a "
|
| 248 |
"magical and romantic feeling to the scene, the view is stunning captured with beautiful photography.",
|
| 249 |
+
None,
|
| 250 |
+
None,
|
| 251 |
+
],
|
| 252 |
+
[
|
| 253 |
+
"Image-to-Video",
|
| 254 |
+
"A towering emerald wave surges forward, its crest curling with raw power and energy. Sunlight glints off the translucent water, illuminating the intricate textures and deep green hues within the wave’s body. A thick spray erupts from the breaking crest, casting a misty veil that dances above the churning surface. As the perspective widens, the immense scale of the wave becomes apparent, revealing the restless expanse of the ocean stretching beyond. The scene captures the ocean’s untamed beauty and relentless force, with every droplet and ripple shimmering in the light. The dynamic motion and vivid colors evoke both awe and respect for nature’s might.",
|
| 255 |
+
"https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/helios/wave.jpg",
|
| 256 |
+
None,
|
| 257 |
+
],
|
| 258 |
+
[
|
| 259 |
+
"Video-to-Video",
|
| 260 |
+
"A bright yellow Lamborghini Huracn Tecnica speeds along a curving mountain road, surrounded by lush green trees under a partly cloudy sky. The car's sleek design and vibrant color stand out against the natural backdrop, emphasizing its dynamic movement. The road curves gently, with a guardrail visible on one side, adding depth to the scene. The motion blur captures the sense of speed and energy, creating a thrilling and exhilarating atmosphere. A front-facing shot from a slightly elevated angle, highlighting the car's aggressive stance and the surrounding greenery.",
|
| 261 |
+
None,
|
| 262 |
+
"https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/helios/car.mp4",
|
| 263 |
],
|
| 264 |
],
|
| 265 |
+
inputs=[mode, prompt, image_input, video_input],
|
| 266 |
label="Example Prompts",
|
| 267 |
)
|
| 268 |
|
| 269 |
if __name__ == "__main__":
|
| 270 |
+
demo.launch(share=True, css=CSS, theme=gr.themes.Soft())
|