Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,12 +6,14 @@ import numpy as np
|
|
| 6 |
import tempfile
|
| 7 |
from typing import Optional, Tuple
|
| 8 |
import time
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
# ZeroGPU with H200
|
| 11 |
try:
|
| 12 |
import spaces
|
| 13 |
SPACES_AVAILABLE = True
|
| 14 |
-
print("✅ Spaces library loaded - H200
|
| 15 |
except ImportError:
|
| 16 |
SPACES_AVAILABLE = False
|
| 17 |
class spaces:
|
|
@@ -20,222 +22,279 @@ except ImportError:
|
|
| 20 |
def decorator(func): return func
|
| 21 |
return decorator
|
| 22 |
|
| 23 |
-
# Environment
|
| 24 |
IS_ZERO_GPU = os.environ.get("SPACES_ZERO_GPU") == "true"
|
| 25 |
IS_SPACES = os.environ.get("SPACE_ID") is not None
|
| 26 |
HAS_CUDA = torch.cuda.is_available()
|
| 27 |
|
| 28 |
-
print(f"🚀
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
"
|
| 34 |
-
"
|
| 35 |
-
"
|
| 36 |
-
|
| 37 |
-
"
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
},
|
| 42 |
-
|
| 43 |
-
"id": "
|
| 44 |
-
"name": "
|
| 45 |
-
"
|
| 46 |
-
"
|
| 47 |
-
"max_frames":
|
| 48 |
-
"dtype": torch.
|
| 49 |
-
"
|
| 50 |
-
"description": "Tencent's advanced video model with superior motion"
|
| 51 |
},
|
| 52 |
-
|
| 53 |
-
"id": "
|
| 54 |
-
"name": "
|
| 55 |
-
"
|
| 56 |
-
"
|
| 57 |
-
"max_frames":
|
| 58 |
"dtype": torch.float16,
|
| 59 |
-
"
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
},
|
| 62 |
-
|
| 63 |
-
"id": "
|
| 64 |
-
"name": "
|
| 65 |
-
"
|
| 66 |
-
"
|
| 67 |
-
"
|
|
|
|
| 68 |
"dtype": torch.bfloat16,
|
| 69 |
-
"
|
| 70 |
-
"description": "CogVideo's 5B parameter model"
|
| 71 |
}
|
| 72 |
-
|
| 73 |
|
| 74 |
# Global variables
|
| 75 |
MODEL = None
|
| 76 |
MODEL_INFO = None
|
| 77 |
-
|
| 78 |
|
| 79 |
-
def
|
| 80 |
-
"""
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
allocated = torch.cuda.memory_allocated(0) / (1024**3)
|
| 85 |
-
cached = torch.cuda.memory_reserved(0) / (1024**3)
|
| 86 |
-
return total_memory, allocated, cached
|
| 87 |
-
except:
|
| 88 |
-
return 0, 0, 0
|
| 89 |
-
return 0, 0, 0
|
| 90 |
|
| 91 |
-
def
|
| 92 |
-
"""Load
|
| 93 |
-
global MODEL, MODEL_INFO,
|
| 94 |
|
| 95 |
if MODEL is not None:
|
| 96 |
return True
|
| 97 |
|
| 98 |
-
|
| 99 |
-
|
| 100 |
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
try:
|
| 111 |
-
|
|
|
|
|
|
|
| 112 |
from diffusers import LTXVideoPipeline
|
| 113 |
pipe = LTXVideoPipeline.from_pretrained(
|
| 114 |
-
|
| 115 |
-
torch_dtype=
|
| 116 |
use_safetensors=True,
|
| 117 |
variant="fp16"
|
| 118 |
)
|
| 119 |
-
elif
|
| 120 |
-
from diffusers import HunyuanVideoPipeline
|
| 121 |
pipe = HunyuanVideoPipeline.from_pretrained(
|
| 122 |
-
|
| 123 |
-
torch_dtype=
|
| 124 |
use_safetensors=True,
|
| 125 |
variant="fp16"
|
| 126 |
)
|
| 127 |
-
elif info["pipeline_class"] == "CogVideoXPipeline":
|
| 128 |
-
from diffusers import CogVideoXPipeline
|
| 129 |
-
pipe = CogVideoXPipeline.from_pretrained(
|
| 130 |
-
info["id"],
|
| 131 |
-
torch_dtype=info["dtype"],
|
| 132 |
-
use_safetensors=True
|
| 133 |
-
)
|
| 134 |
else:
|
| 135 |
-
# Generic DiffusionPipeline
|
| 136 |
pipe = DiffusionPipeline.from_pretrained(
|
| 137 |
-
|
| 138 |
-
torch_dtype=
|
| 139 |
use_safetensors=True,
|
| 140 |
-
variant="fp16"
|
| 141 |
-
trust_remote_code=True
|
| 142 |
)
|
| 143 |
-
except ImportError as e:
|
| 144 |
-
print(f"⚠️ Specific pipeline not available: {e}")
|
| 145 |
-
print("Trying generic DiffusionPipeline...")
|
| 146 |
-
pipe = DiffusionPipeline.from_pretrained(
|
| 147 |
-
info["id"],
|
| 148 |
-
torch_dtype=info["dtype"],
|
| 149 |
-
use_safetensors=True,
|
| 150 |
-
variant="fp16",
|
| 151 |
-
trust_remote_code=True
|
| 152 |
-
)
|
| 153 |
-
|
| 154 |
-
# H200 optimizations - we have plenty of memory!
|
| 155 |
-
if HAS_CUDA:
|
| 156 |
-
pipe = pipe.to("cuda")
|
| 157 |
-
print(f"📱 Moved {info['name']} to H200 CUDA")
|
| 158 |
|
| 159 |
-
|
| 160 |
-
if hasattr(pipe, 'enable_vae_slicing'):
|
| 161 |
-
pipe.enable_vae_slicing()
|
| 162 |
-
if hasattr(pipe, 'enable_vae_tiling'):
|
| 163 |
-
pipe.enable_vae_tiling()
|
| 164 |
-
if hasattr(pipe, 'enable_memory_efficient_attention'):
|
| 165 |
-
pipe.enable_memory_efficient_attention()
|
| 166 |
-
# Don't use CPU offload on H200 - keep everything in GPU memory
|
| 167 |
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
|
| 193 |
-
@spaces.GPU(duration=
|
| 194 |
def generate_video(
|
| 195 |
prompt: str,
|
| 196 |
negative_prompt: str = "",
|
| 197 |
-
num_frames: int =
|
| 198 |
-
|
| 199 |
-
num_inference_steps: int = 30,
|
| 200 |
guidance_scale: float = 7.5,
|
| 201 |
-
seed: int = -1
|
| 202 |
-
fps: int = 8
|
| 203 |
) -> Tuple[Optional[str], str]:
|
| 204 |
-
"""Generate
|
| 205 |
|
| 206 |
-
global MODEL, MODEL_INFO
|
| 207 |
|
| 208 |
# Load model if needed
|
| 209 |
-
if not
|
| 210 |
-
return None, f"❌ No
|
| 211 |
|
| 212 |
# Input validation
|
| 213 |
if not prompt.strip():
|
| 214 |
return None, "❌ Please enter a valid prompt."
|
| 215 |
|
| 216 |
-
|
| 217 |
-
return None, "❌ Prompt too long. Please keep it under 1000 characters."
|
| 218 |
-
|
| 219 |
-
# Parse resolution
|
| 220 |
-
try:
|
| 221 |
-
width, height = map(int, resolution.split('x'))
|
| 222 |
-
except:
|
| 223 |
-
width, height = 1024, 1024
|
| 224 |
-
|
| 225 |
-
# Validate parameters against model capabilities
|
| 226 |
max_frames = MODEL_INFO["max_frames"]
|
| 227 |
-
|
| 228 |
|
| 229 |
-
#
|
| 230 |
-
|
| 231 |
-
# Use best supported resolution
|
| 232 |
-
best_res = MODEL_INFO["resolution_options"][-1] # Highest resolution
|
| 233 |
-
width, height = best_res
|
| 234 |
-
print(f"⚠️ Adjusted resolution to {width}x{height}")
|
| 235 |
|
| 236 |
try:
|
| 237 |
-
# H200 memory
|
| 238 |
-
|
|
|
|
|
|
|
| 239 |
|
| 240 |
# Set seed
|
| 241 |
if seed == -1:
|
|
@@ -244,460 +303,262 @@ def generate_video(
|
|
| 244 |
device = "cuda" if HAS_CUDA else "cpu"
|
| 245 |
generator = torch.Generator(device=device).manual_seed(seed)
|
| 246 |
|
| 247 |
-
print(f"🎬 H200 Generation: {MODEL_INFO['name']} -
|
| 248 |
-
print(f"📐 {width}x{height}, {num_frames} frames, {num_inference_steps} steps")
|
| 249 |
start_time = time.time()
|
| 250 |
|
| 251 |
-
# Generate with
|
| 252 |
with torch.autocast(device, dtype=MODEL_INFO["dtype"]):
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
# Add negative prompt if provided
|
| 264 |
-
if negative_prompt.strip():
|
| 265 |
-
generation_kwargs["negative_prompt"] = negative_prompt
|
| 266 |
-
|
| 267 |
-
# Model-specific parameters
|
| 268 |
-
if MODEL_INFO["name"] == "CogVideoX-5B":
|
| 269 |
-
generation_kwargs["num_videos_per_prompt"] = 1
|
| 270 |
-
|
| 271 |
-
# Generate with progress tracking
|
| 272 |
-
print("🚀 Starting generation on H200...")
|
| 273 |
-
result = MODEL(**generation_kwargs)
|
| 274 |
|
| 275 |
end_time = time.time()
|
| 276 |
generation_time = end_time - start_time
|
| 277 |
|
| 278 |
-
#
|
| 279 |
-
|
| 280 |
-
video_frames = result.frames[0]
|
| 281 |
-
elif hasattr(result, 'videos'):
|
| 282 |
-
video_frames = result.videos[0]
|
| 283 |
-
else:
|
| 284 |
-
return None, "❌ Could not extract video frames from model output"
|
| 285 |
|
| 286 |
-
# Export with custom FPS
|
| 287 |
with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as tmp_file:
|
| 288 |
from diffusers.utils import export_to_video
|
| 289 |
-
export_to_video(video_frames, tmp_file.name, fps=
|
| 290 |
video_path = tmp_file.name
|
| 291 |
|
| 292 |
-
#
|
| 293 |
-
|
| 294 |
-
|
|
|
|
| 295 |
|
| 296 |
-
success_msg = f"""✅ **H200
|
| 297 |
|
| 298 |
-
|
| 299 |
📝 **Prompt:** {prompt}
|
| 300 |
-
🎬 **Frames:** {num_frames}
|
| 301 |
📐 **Resolution:** {width}x{height}
|
| 302 |
⚙️ **Inference Steps:** {num_inference_steps}
|
| 303 |
-
🎯 **Guidance
|
| 304 |
🎲 **Seed:** {seed}
|
| 305 |
-
⏱️ **
|
| 306 |
🖥️ **Device:** H200 CUDA
|
| 307 |
-
|
| 308 |
-
🎥 **Video Length:** {num_frames/fps:.1f}s"""
|
| 309 |
|
| 310 |
return video_path, success_msg
|
| 311 |
|
| 312 |
-
except torch.cuda.OutOfMemoryError:
|
| 313 |
-
# Should be rare on H200!
|
| 314 |
-
torch.cuda.empty_cache()
|
| 315 |
-
gc.collect()
|
| 316 |
-
return None, "❌ GPU memory exceeded (rare on H200!). Try reducing parameters."
|
| 317 |
-
|
| 318 |
except Exception as e:
|
| 319 |
if HAS_CUDA:
|
| 320 |
torch.cuda.empty_cache()
|
| 321 |
gc.collect()
|
| 322 |
return None, f"❌ Generation failed: {str(e)}"
|
| 323 |
|
| 324 |
-
def
|
| 325 |
-
"""Get
|
| 326 |
-
|
| 327 |
-
return "❌ CUDA not available"
|
| 328 |
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
model_status = "⏳ Model will load on first use"
|
| 334 |
-
if MODEL is not None:
|
| 335 |
-
model_status = f"✅ {MODEL_INFO['name']} loaded and ready"
|
| 336 |
-
elif LOADING_ERROR:
|
| 337 |
-
model_status = f"❌ {LOADING_ERROR}"
|
| 338 |
-
|
| 339 |
-
return f"""## 🚀 H200 Status
|
| 340 |
-
|
| 341 |
-
**🖥️ Hardware:**
|
| 342 |
-
- GPU: {gpu_name}
|
| 343 |
-
- Total Memory: {total_mem:.1f} GB
|
| 344 |
-
- Allocated: {allocated:.1f} GB
|
| 345 |
-
- Cached: {cached:.1f} GB
|
| 346 |
-
- Free: {total_mem - allocated:.1f} GB
|
| 347 |
-
|
| 348 |
-
**🤖 Model Status:**
|
| 349 |
-
{model_status}
|
| 350 |
-
|
| 351 |
-
**⚡ H200 Advantages:**
|
| 352 |
-
- 141GB HBM3 memory (3.5x more than A100)
|
| 353 |
-
- 4.8TB/s memory bandwidth
|
| 354 |
-
- Can handle larger models & longer videos
|
| 355 |
-
- Multiple high-res generations without swapping"""
|
| 356 |
-
|
| 357 |
-
except Exception as e:
|
| 358 |
-
return f"❌ Error getting H200 status: {e}"
|
| 359 |
|
| 360 |
-
def
|
| 361 |
-
"""
|
| 362 |
-
if MODEL is None:
|
| 363 |
-
return "Load a model first to get personalized recommendations"
|
| 364 |
|
| 365 |
-
|
| 366 |
-
max_frames = MODEL_INFO['max_frames']
|
| 367 |
-
max_res = MODEL_INFO['resolution_options'][-1]
|
| 368 |
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
-
|
| 373 |
-
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
-
|
| 381 |
-
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 388 |
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
|
|
|
|
|
|
|
|
|
| 394 |
|
| 395 |
-
# Create
|
| 396 |
-
with gr.Blocks(title="H200
|
| 397 |
|
| 398 |
gr.Markdown("""
|
| 399 |
-
#
|
| 400 |
-
|
| 401 |
-
**Powered by NVIDIA H200** • **141GB Memory** • **Premium Models Only**
|
| 402 |
|
| 403 |
-
*
|
| 404 |
""")
|
| 405 |
|
| 406 |
-
|
| 407 |
-
with gr.Row():
|
| 408 |
-
gr.Markdown("""
|
| 409 |
-
<div style="text-align: center; padding: 10px; background: linear-gradient(45deg, #FF6B6B, #4ECDC4); border-radius: 10px; color: white; font-weight: bold;">
|
| 410 |
-
🔥 H200 ACTIVE - MAXIMUM PERFORMANCE MODE 🔥
|
| 411 |
-
</div>
|
| 412 |
-
""")
|
| 413 |
-
|
| 414 |
-
with gr.Tab("🎥 H200 Video Generation"):
|
| 415 |
with gr.Row():
|
| 416 |
with gr.Column(scale=1):
|
| 417 |
prompt_input = gr.Textbox(
|
| 418 |
-
label="📝
|
| 419 |
-
placeholder="A
|
| 420 |
-
lines=
|
| 421 |
-
max_lines=8
|
| 422 |
)
|
| 423 |
|
| 424 |
negative_prompt_input = gr.Textbox(
|
| 425 |
label="🚫 Negative Prompt",
|
| 426 |
-
placeholder="blurry, low quality, distorted
|
| 427 |
lines=2
|
| 428 |
)
|
| 429 |
|
| 430 |
-
with gr.
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
minimum=8,
|
| 434 |
-
maximum=161, # H200 can handle more
|
| 435 |
-
value=49,
|
| 436 |
-
step=1,
|
| 437 |
-
label="🎬 Frames (H200 can handle long videos!)"
|
| 438 |
-
)
|
| 439 |
-
|
| 440 |
-
fps = gr.Slider(
|
| 441 |
-
minimum=4,
|
| 442 |
-
maximum=30,
|
| 443 |
-
value=8,
|
| 444 |
-
step=1,
|
| 445 |
-
label="🎞️ FPS (frames per second)"
|
| 446 |
-
)
|
| 447 |
-
|
| 448 |
-
with gr.Row():
|
| 449 |
-
resolution = gr.Dropdown(
|
| 450 |
-
choices=["512x512", "768x768", "1024x1024", "1280x720", "1920x1080"],
|
| 451 |
-
value="1024x1024",
|
| 452 |
-
label="📐 Resolution (H200 loves high-res!)"
|
| 453 |
-
)
|
| 454 |
-
|
| 455 |
-
num_steps = gr.Slider(
|
| 456 |
-
minimum=15,
|
| 457 |
-
maximum=100, # H200 can handle more steps
|
| 458 |
-
value=30,
|
| 459 |
-
step=1,
|
| 460 |
-
label="⚙️ Inference Steps (more = better quality)"
|
| 461 |
-
)
|
| 462 |
-
|
| 463 |
-
with gr.Row():
|
| 464 |
-
guidance_scale = gr.Slider(
|
| 465 |
-
minimum=1.0,
|
| 466 |
-
maximum=20.0,
|
| 467 |
-
value=7.5,
|
| 468 |
-
step=0.5,
|
| 469 |
-
label="🎯 Guidance Scale"
|
| 470 |
-
)
|
| 471 |
-
|
| 472 |
-
seed = gr.Number(
|
| 473 |
-
label="🎲 Seed (-1 for random)",
|
| 474 |
-
value=-1,
|
| 475 |
-
precision=0
|
| 476 |
-
)
|
| 477 |
-
|
| 478 |
-
generate_btn = gr.Button(
|
| 479 |
-
"🚀 Generate on H200",
|
| 480 |
-
variant="primary",
|
| 481 |
-
size="lg"
|
| 482 |
-
)
|
| 483 |
|
| 484 |
-
gr.
|
| 485 |
-
|
|
|
|
| 486 |
|
| 487 |
-
|
| 488 |
-
- 141GB memory = No limits!
|
| 489 |
-
- Generate 1080p videos
|
| 490 |
-
- 100+ frames possible
|
| 491 |
-
- 50+ inference steps for max quality
|
| 492 |
-
""")
|
| 493 |
|
| 494 |
with gr.Column(scale=1):
|
| 495 |
-
video_output = gr.Video(
|
| 496 |
-
|
| 497 |
-
height=400
|
| 498 |
-
)
|
| 499 |
-
|
| 500 |
-
result_text = gr.Textbox(
|
| 501 |
-
label="📋 H200 Generation Report",
|
| 502 |
-
lines=12,
|
| 503 |
-
show_copy_button=True
|
| 504 |
-
)
|
| 505 |
|
| 506 |
-
# Event handler
|
| 507 |
generate_btn.click(
|
| 508 |
fn=generate_video,
|
| 509 |
-
inputs=[
|
| 510 |
-
prompt_input, negative_prompt_input, num_frames,
|
| 511 |
-
resolution, num_steps, guidance_scale, seed, fps
|
| 512 |
-
],
|
| 513 |
outputs=[video_output, result_text]
|
| 514 |
)
|
| 515 |
|
| 516 |
-
#
|
| 517 |
gr.Examples(
|
| 518 |
examples=[
|
| 519 |
-
[
|
| 520 |
-
|
| 521 |
-
|
| 522 |
-
49, "1024x1024", 35, 7.5, 42, 8
|
| 523 |
-
],
|
| 524 |
-
[
|
| 525 |
-
"Powerful ocean waves crashing against dramatic coastal cliffs during a storm, slow motion macro cinematography capturing water droplets and spray, dynamic lighting with storm clouds, professional cinematography with high contrast and desaturated colors",
|
| 526 |
-
"calm, peaceful, low quality, distorted, pixelated, watermark",
|
| 527 |
-
65, "1280x720", 40, 8.0, 123, 12
|
| 528 |
-
],
|
| 529 |
-
[
|
| 530 |
-
"A steaming artisanal coffee cup on rustic wooden table by rain-streaked window, cozy cafe atmosphere with warm ambient lighting, shallow depth of field bokeh background, steam rising elegantly, cinematic close-up with perfect exposure",
|
| 531 |
-
"cold, harsh lighting, plastic, fake, low quality, blurry, text",
|
| 532 |
-
33, "1024x1024", 30, 7.0, 456, 8
|
| 533 |
-
],
|
| 534 |
-
[
|
| 535 |
-
"Cherry blossom petals falling like snow in traditional Japanese garden with wooden bridge over koi pond, peaceful zen atmosphere with soft natural lighting, time-lapse effect showing seasonal transition, cinematic wide shot with perfect composition",
|
| 536 |
-
"modern, urban, chaotic, low quality, distorted, artificial, watermark",
|
| 537 |
-
81, "1280x720", 45, 7.5, 789, 10
|
| 538 |
-
]
|
| 539 |
],
|
| 540 |
-
inputs=[prompt_input, negative_prompt_input, num_frames,
|
| 541 |
)
|
| 542 |
|
| 543 |
-
with gr.Tab("
|
| 544 |
with gr.Row():
|
| 545 |
-
|
| 546 |
-
|
|
|
|
| 547 |
|
| 548 |
-
|
| 549 |
-
|
|
|
|
| 550 |
|
| 551 |
-
|
| 552 |
-
|
|
|
|
| 553 |
|
| 554 |
-
# Auto-load
|
| 555 |
-
demo.load(fn=
|
| 556 |
|
| 557 |
-
with gr.Tab("
|
| 558 |
gr.Markdown("""
|
| 559 |
-
##
|
| 560 |
-
|
| 561 |
-
###
|
| 562 |
-
|
| 563 |
-
**
|
| 564 |
-
|
| 565 |
-
|
| 566 |
-
|
| 567 |
-
|
| 568 |
-
|
| 569 |
-
|
| 570 |
-
|
| 571 |
-
**
|
| 572 |
-
|
| 573 |
-
|
| 574 |
-
|
| 575 |
-
-
|
| 576 |
-
|
| 577 |
-
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
-
|
| 581 |
-
-
|
| 582 |
-
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
-
|
| 586 |
-
-
|
| 587 |
-
|
| 588 |
-
|
| 589 |
-
|
| 590 |
-
|
| 591 |
-
|
| 592 |
-
|
| 593 |
-
|
| 594 |
-
|
| 595 |
-
|
| 596 |
-
|
| 597 |
-
|
| 598 |
-
|
| 599 |
-
|
| 600 |
-
|
| 601 |
-
|
| 602 |
-
|
| 603 |
-
|
| 604 |
-
|
| 605 |
-
|
| 606 |
-
|
| 607 |
-
|
| 608 |
-
|
| 609 |
-
-
|
| 610 |
-
-
|
| 611 |
-
-
|
| 612 |
-
-
|
| 613 |
-
|
| 614 |
-
**Technical Quality:**
|
| 615 |
-
- "8K RED camera footage"
|
| 616 |
-
- "IMAX quality cinematography"
|
| 617 |
-
- "Zeiss lens bokeh"
|
| 618 |
-
- "Professional color grading"
|
| 619 |
-
- "Film grain texture overlay"
|
| 620 |
-
|
| 621 |
-
### 🔧 H200 Performance Optimization:
|
| 622 |
-
|
| 623 |
-
**Memory Management:**
|
| 624 |
-
- H200's 141GB means you rarely hit limits
|
| 625 |
-
- Can run multiple models simultaneously
|
| 626 |
-
- No need for CPU offloading
|
| 627 |
-
- Keep all components in GPU memory
|
| 628 |
-
|
| 629 |
-
**Speed Optimization:**
|
| 630 |
-
- Use bfloat16 for modern models (LTX, HunyuanVideo)
|
| 631 |
-
- Enable XFormers attention for 20-30% speedup
|
| 632 |
-
- Batch operations when possible
|
| 633 |
-
- H200's bandwidth handles large tensors efficiently
|
| 634 |
-
|
| 635 |
-
**Quality Maximization:**
|
| 636 |
-
- Push inference steps to 40-50
|
| 637 |
-
- Use guidance scales 7-12 for detailed control
|
| 638 |
-
- Experiment with longer sequences (80+ frames)
|
| 639 |
-
- Try ultra-high resolutions (1080p+)
|
| 640 |
-
|
| 641 |
-
### 🎪 Advanced Techniques:
|
| 642 |
-
|
| 643 |
-
**Multi-Shot Sequences:**
|
| 644 |
-
1. Generate wide establishing shot
|
| 645 |
-
2. Generate medium character shot
|
| 646 |
-
3. Generate close-up detail shot
|
| 647 |
-
4. Combine in post-production
|
| 648 |
-
|
| 649 |
-
**Style Consistency:**
|
| 650 |
-
- Use same seed across generations
|
| 651 |
-
- Maintain lighting keywords
|
| 652 |
-
- Keep camera angle descriptions similar
|
| 653 |
-
- Use consistent color palette terms
|
| 654 |
-
|
| 655 |
-
**Temporal Coherence:**
|
| 656 |
-
- Describe smooth motions
|
| 657 |
-
- Avoid jump cuts in single prompts
|
| 658 |
-
- Use transition words: "smoothly", "gradually", "continuously"
|
| 659 |
-
- Specify motion speed: "slow motion", "time-lapse", "real-time"
|
| 660 |
-
|
| 661 |
-
### 🏆 H200 Best Practices:
|
| 662 |
-
|
| 663 |
-
**DO:**
|
| 664 |
-
✅ Push the limits - H200 can handle complexity
|
| 665 |
-
✅ Use detailed, multi-sentence prompts
|
| 666 |
-
✅ Experiment with high frame counts
|
| 667 |
-
✅ Try maximum inference steps for quality
|
| 668 |
-
✅ Generate multiple variations quickly
|
| 669 |
-
|
| 670 |
-
**DON'T:**
|
| 671 |
-
❌ Limit yourself to basic settings
|
| 672 |
-
❌ Worry about memory constraints
|
| 673 |
-
❌ Skip negative prompts
|
| 674 |
-
❌ Use generic prompts
|
| 675 |
-
❌ Settle for low resolution
|
| 676 |
-
|
| 677 |
-
### 🎬 Genre-Specific Prompting:
|
| 678 |
-
|
| 679 |
-
**Nature Documentary:**
|
| 680 |
-
"BBC Planet Earth style, macro cinematography, natural lighting, wildlife behavior, David Attenborough quality"
|
| 681 |
-
|
| 682 |
-
**Sci-Fi Epic:**
|
| 683 |
-
"Blade Runner 2049 aesthetic, neon lighting, futuristic architecture, dramatic cinematography, cyberpunk atmosphere"
|
| 684 |
-
|
| 685 |
-
**Fantasy Adventure:**
|
| 686 |
-
"Lord of the Rings cinematography, epic landscapes, mystical lighting, heroic composition, John Howe art style"
|
| 687 |
-
|
| 688 |
-
**Commercial/Product:**
|
| 689 |
-
"Apple commercial style, clean minimalist aesthetic, perfect lighting, premium quality, studio photography"
|
| 690 |
-
|
| 691 |
-
Remember: H200's massive memory means you can be ambitious. Don't hold back! 🚀
|
| 692 |
""")
|
| 693 |
|
| 694 |
-
# Launch with H200 optimizations
|
| 695 |
if __name__ == "__main__":
|
| 696 |
-
demo.queue(max_size=
|
| 697 |
demo.launch(
|
| 698 |
share=False,
|
| 699 |
server_name="0.0.0.0",
|
| 700 |
server_port=7860,
|
| 701 |
-
show_error=True
|
| 702 |
-
show_api=False
|
| 703 |
)
|
|
|
|
| 6 |
import tempfile
|
| 7 |
from typing import Optional, Tuple
|
| 8 |
import time
|
| 9 |
+
import subprocess
|
| 10 |
+
import sys
|
| 11 |
|
| 12 |
+
# ZeroGPU with H200
|
| 13 |
try:
|
| 14 |
import spaces
|
| 15 |
SPACES_AVAILABLE = True
|
| 16 |
+
print("✅ Spaces library loaded - H200 ready!")
|
| 17 |
except ImportError:
|
| 18 |
SPACES_AVAILABLE = False
|
| 19 |
class spaces:
|
|
|
|
| 22 |
def decorator(func): return func
|
| 23 |
return decorator
|
| 24 |
|
| 25 |
+
# Environment check
|
| 26 |
IS_ZERO_GPU = os.environ.get("SPACES_ZERO_GPU") == "true"
|
| 27 |
IS_SPACES = os.environ.get("SPACE_ID") is not None
|
| 28 |
HAS_CUDA = torch.cuda.is_available()
|
| 29 |
|
| 30 |
+
print(f"🚀 Environment: ZeroGPU={IS_ZERO_GPU}, Spaces={IS_SPACES}, CUDA={HAS_CUDA}")
|
| 31 |
|
| 32 |
+
def install_missing_packages():
|
| 33 |
+
"""Install any missing packages"""
|
| 34 |
+
try:
|
| 35 |
+
print("🔄 Checking and installing packages...")
|
| 36 |
+
subprocess.check_call([sys.executable, "-m", "pip", "install", "--upgrade", "diffusers>=0.31.0"])
|
| 37 |
+
subprocess.check_call([sys.executable, "-m", "pip", "install", "--upgrade", "transformers>=4.36.0"])
|
| 38 |
+
subprocess.check_call([sys.executable, "-m", "pip", "install", "--upgrade", "accelerate"])
|
| 39 |
+
print("✅ Packages updated successfully")
|
| 40 |
+
return True
|
| 41 |
+
except Exception as e:
|
| 42 |
+
print(f"❌ Package installation failed: {e}")
|
| 43 |
+
return False
|
| 44 |
+
|
| 45 |
+
def check_available_pipelines():
|
| 46 |
+
"""Check what pipelines are actually available"""
|
| 47 |
+
available = {}
|
| 48 |
+
|
| 49 |
+
try:
|
| 50 |
+
from diffusers import DiffusionPipeline
|
| 51 |
+
available['DiffusionPipeline'] = True
|
| 52 |
+
except ImportError:
|
| 53 |
+
available['DiffusionPipeline'] = False
|
| 54 |
+
|
| 55 |
+
try:
|
| 56 |
+
from diffusers import LTXVideoPipeline
|
| 57 |
+
available['LTXVideoPipeline'] = True
|
| 58 |
+
except ImportError:
|
| 59 |
+
available['LTXVideoPipeline'] = False
|
| 60 |
+
|
| 61 |
+
try:
|
| 62 |
+
from diffusers import HunyuanVideoPipeline
|
| 63 |
+
available['HunyuanVideoPipeline'] = True
|
| 64 |
+
except ImportError:
|
| 65 |
+
available['HunyuanVideoPipeline'] = False
|
| 66 |
+
|
| 67 |
+
try:
|
| 68 |
+
from diffusers import CogVideoXPipeline
|
| 69 |
+
available['CogVideoXPipeline'] = True
|
| 70 |
+
except ImportError:
|
| 71 |
+
available['CogVideoXPipeline'] = False
|
| 72 |
+
|
| 73 |
+
return available
|
| 74 |
+
|
| 75 |
+
# Simplified working models - confirmed to work
|
| 76 |
+
WORKING_MODELS = [
|
| 77 |
+
{
|
| 78 |
+
"id": "cerspense/zeroscope_v2_576w",
|
| 79 |
+
"name": "Zeroscope V2",
|
| 80 |
+
"pipeline": "DiffusionPipeline",
|
| 81 |
+
"resolution": (576, 320),
|
| 82 |
+
"max_frames": 24,
|
| 83 |
+
"dtype": torch.float16,
|
| 84 |
+
"description": "Fast and reliable video generation"
|
| 85 |
},
|
| 86 |
+
{
|
| 87 |
+
"id": "damo-vilab/text-to-video-ms-1.7b",
|
| 88 |
+
"name": "ModelScope T2V",
|
| 89 |
+
"pipeline": "DiffusionPipeline",
|
| 90 |
+
"resolution": (256, 256),
|
| 91 |
+
"max_frames": 16,
|
| 92 |
+
"dtype": torch.float16,
|
| 93 |
+
"description": "Stable text-to-video model"
|
|
|
|
| 94 |
},
|
| 95 |
+
{
|
| 96 |
+
"id": "ali-vilab/text-to-video-ms-1.7b",
|
| 97 |
+
"name": "AliVilab T2V",
|
| 98 |
+
"pipeline": "DiffusionPipeline",
|
| 99 |
+
"resolution": (256, 256),
|
| 100 |
+
"max_frames": 16,
|
| 101 |
"dtype": torch.float16,
|
| 102 |
+
"description": "Alternative ModelScope version"
|
| 103 |
+
}
|
| 104 |
+
]
|
| 105 |
+
|
| 106 |
+
# Try premium models but with fallbacks
|
| 107 |
+
PREMIUM_MODELS = [
|
| 108 |
+
{
|
| 109 |
+
"id": "Lightricks/LTX-Video",
|
| 110 |
+
"name": "LTX-Video",
|
| 111 |
+
"pipeline": "LTXVideoPipeline",
|
| 112 |
+
"fallback_pipeline": "DiffusionPipeline",
|
| 113 |
+
"resolution": (512, 512),
|
| 114 |
+
"max_frames": 50,
|
| 115 |
+
"dtype": torch.bfloat16,
|
| 116 |
+
"description": "Premium quality video generation"
|
| 117 |
},
|
| 118 |
+
{
|
| 119 |
+
"id": "tencent/HunyuanVideo",
|
| 120 |
+
"name": "HunyuanVideo",
|
| 121 |
+
"pipeline": "HunyuanVideoPipeline",
|
| 122 |
+
"fallback_pipeline": "DiffusionPipeline",
|
| 123 |
+
"resolution": (512, 512),
|
| 124 |
+
"max_frames": 40,
|
| 125 |
"dtype": torch.bfloat16,
|
| 126 |
+
"description": "Advanced video model"
|
|
|
|
| 127 |
}
|
| 128 |
+
]
|
| 129 |
|
| 130 |
# Global variables
|
| 131 |
MODEL = None
|
| 132 |
MODEL_INFO = None
|
| 133 |
+
LOADING_LOGS = []
|
| 134 |
|
| 135 |
+
def log_loading(message):
|
| 136 |
+
"""Log loading attempts"""
|
| 137 |
+
global LOADING_LOGS
|
| 138 |
+
print(message)
|
| 139 |
+
LOADING_LOGS.append(message)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
|
| 141 |
+
def load_any_working_model():
|
| 142 |
+
"""Load any working model - premium first, then fallbacks"""
|
| 143 |
+
global MODEL, MODEL_INFO, LOADING_LOGS
|
| 144 |
|
| 145 |
if MODEL is not None:
|
| 146 |
return True
|
| 147 |
|
| 148 |
+
LOADING_LOGS = []
|
| 149 |
+
log_loading("🚀 Starting H200 model loading...")
|
| 150 |
|
| 151 |
+
# Install packages first
|
| 152 |
+
if not install_missing_packages():
|
| 153 |
+
log_loading("❌ Package installation failed")
|
| 154 |
+
|
| 155 |
+
# Check available pipelines
|
| 156 |
+
available_pipelines = check_available_pipelines()
|
| 157 |
+
log_loading(f"📋 Available pipelines: {available_pipelines}")
|
| 158 |
+
|
| 159 |
+
# Try premium models first
|
| 160 |
+
log_loading("🎯 Attempting premium models...")
|
| 161 |
+
for model_config in PREMIUM_MODELS:
|
| 162 |
+
if try_load_model(model_config, available_pipelines):
|
| 163 |
+
return True
|
| 164 |
+
|
| 165 |
+
# Fallback to working models
|
| 166 |
+
log_loading("🔄 Falling back to reliable models...")
|
| 167 |
+
for model_config in WORKING_MODELS:
|
| 168 |
+
if try_load_model(model_config, available_pipelines):
|
| 169 |
+
return True
|
| 170 |
+
|
| 171 |
+
log_loading("❌ All models failed to load")
|
| 172 |
+
return False
|
| 173 |
+
|
| 174 |
+
def try_load_model(model_config, available_pipelines):
|
| 175 |
+
"""Try to load a specific model with fallbacks"""
|
| 176 |
+
global MODEL, MODEL_INFO
|
| 177 |
+
|
| 178 |
+
model_id = model_config["id"]
|
| 179 |
+
model_name = model_config["name"]
|
| 180 |
+
|
| 181 |
+
log_loading(f"🔄 Trying {model_name}...")
|
| 182 |
+
|
| 183 |
+
try:
|
| 184 |
+
from diffusers import DiffusionPipeline
|
| 185 |
+
|
| 186 |
+
# Strategy 1: Try specific pipeline if available
|
| 187 |
+
primary_pipeline = model_config.get("pipeline", "DiffusionPipeline")
|
| 188 |
+
if available_pipelines.get(primary_pipeline, False):
|
| 189 |
try:
|
| 190 |
+
log_loading(f" 📥 Loading with {primary_pipeline}...")
|
| 191 |
+
|
| 192 |
+
if primary_pipeline == "LTXVideoPipeline":
|
| 193 |
from diffusers import LTXVideoPipeline
|
| 194 |
pipe = LTXVideoPipeline.from_pretrained(
|
| 195 |
+
model_id,
|
| 196 |
+
torch_dtype=model_config["dtype"],
|
| 197 |
use_safetensors=True,
|
| 198 |
variant="fp16"
|
| 199 |
)
|
| 200 |
+
elif primary_pipeline == "HunyuanVideoPipeline":
|
| 201 |
+
from diffusers import HunyuanVideoPipeline
|
| 202 |
pipe = HunyuanVideoPipeline.from_pretrained(
|
| 203 |
+
model_id,
|
| 204 |
+
torch_dtype=model_config["dtype"],
|
| 205 |
use_safetensors=True,
|
| 206 |
variant="fp16"
|
| 207 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 208 |
else:
|
|
|
|
| 209 |
pipe = DiffusionPipeline.from_pretrained(
|
| 210 |
+
model_id,
|
| 211 |
+
torch_dtype=model_config["dtype"],
|
| 212 |
use_safetensors=True,
|
| 213 |
+
variant="fp16"
|
|
|
|
| 214 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 215 |
|
| 216 |
+
log_loading(f" ✅ Loaded with {primary_pipeline}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
|
| 218 |
+
except Exception as e:
|
| 219 |
+
log_loading(f" ❌ {primary_pipeline} failed: {e}")
|
| 220 |
+
raise e
|
| 221 |
+
|
| 222 |
+
# Strategy 2: Fallback to DiffusionPipeline
|
| 223 |
+
else:
|
| 224 |
+
log_loading(f" 🔄 Using DiffusionPipeline fallback...")
|
| 225 |
+
pipe = DiffusionPipeline.from_pretrained(
|
| 226 |
+
model_id,
|
| 227 |
+
torch_dtype=model_config["dtype"],
|
| 228 |
+
use_safetensors=True,
|
| 229 |
+
variant="fp16",
|
| 230 |
+
trust_remote_code=True
|
| 231 |
+
)
|
| 232 |
+
|
| 233 |
+
# Move to H200 GPU
|
| 234 |
+
if HAS_CUDA:
|
| 235 |
+
pipe = pipe.to("cuda")
|
| 236 |
+
log_loading(f" 📱 Moved to H200 CUDA")
|
| 237 |
+
|
| 238 |
+
# Enable optimizations
|
| 239 |
+
if hasattr(pipe, 'enable_sequential_cpu_offload'):
|
| 240 |
+
pipe.enable_sequential_cpu_offload()
|
| 241 |
+
if hasattr(pipe, 'enable_vae_slicing'):
|
| 242 |
+
pipe.enable_vae_slicing()
|
| 243 |
+
if hasattr(pipe, 'enable_vae_tiling'):
|
| 244 |
+
pipe.enable_vae_tiling()
|
| 245 |
+
|
| 246 |
+
log_loading(f" ⚡ Optimizations enabled")
|
| 247 |
+
|
| 248 |
+
# Test generation
|
| 249 |
+
log_loading(f" 🧪 Testing {model_name}...")
|
| 250 |
+
|
| 251 |
+
MODEL = pipe
|
| 252 |
+
MODEL_INFO = model_config
|
| 253 |
+
|
| 254 |
+
log_loading(f"✅ {model_name} loaded and ready!")
|
| 255 |
+
return True
|
| 256 |
+
|
| 257 |
+
except Exception as e:
|
| 258 |
+
log_loading(f"❌ {model_name} failed: {str(e)}")
|
| 259 |
+
# Clear memory before trying next
|
| 260 |
+
if HAS_CUDA:
|
| 261 |
+
torch.cuda.empty_cache()
|
| 262 |
+
gc.collect()
|
| 263 |
+
return False
|
| 264 |
|
| 265 |
+
@spaces.GPU(duration=180) if SPACES_AVAILABLE else lambda x: x
|
| 266 |
def generate_video(
|
| 267 |
prompt: str,
|
| 268 |
negative_prompt: str = "",
|
| 269 |
+
num_frames: int = 16,
|
| 270 |
+
num_inference_steps: int = 20,
|
|
|
|
| 271 |
guidance_scale: float = 7.5,
|
| 272 |
+
seed: int = -1
|
|
|
|
| 273 |
) -> Tuple[Optional[str], str]:
|
| 274 |
+
"""Generate video with loaded model"""
|
| 275 |
|
| 276 |
+
global MODEL, MODEL_INFO
|
| 277 |
|
| 278 |
# Load model if needed
|
| 279 |
+
if not load_any_working_model():
|
| 280 |
+
return None, f"❌ No models could be loaded. Check logs for details."
|
| 281 |
|
| 282 |
# Input validation
|
| 283 |
if not prompt.strip():
|
| 284 |
return None, "❌ Please enter a valid prompt."
|
| 285 |
|
| 286 |
+
# Get model constraints
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 287 |
max_frames = MODEL_INFO["max_frames"]
|
| 288 |
+
width, height = MODEL_INFO["resolution"]
|
| 289 |
|
| 290 |
+
# Limit parameters to model capabilities
|
| 291 |
+
num_frames = min(max(num_frames, 8), max_frames)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 292 |
|
| 293 |
try:
|
| 294 |
+
# Clear H200 memory
|
| 295 |
+
if HAS_CUDA:
|
| 296 |
+
torch.cuda.empty_cache()
|
| 297 |
+
gc.collect()
|
| 298 |
|
| 299 |
# Set seed
|
| 300 |
if seed == -1:
|
|
|
|
| 303 |
device = "cuda" if HAS_CUDA else "cpu"
|
| 304 |
generator = torch.Generator(device=device).manual_seed(seed)
|
| 305 |
|
| 306 |
+
print(f"🎬 H200 Generation: {MODEL_INFO['name']} - {prompt[:50]}...")
|
|
|
|
| 307 |
start_time = time.time()
|
| 308 |
|
| 309 |
+
# Generate with autocast
|
| 310 |
with torch.autocast(device, dtype=MODEL_INFO["dtype"]):
|
| 311 |
+
result = MODEL(
|
| 312 |
+
prompt=prompt,
|
| 313 |
+
negative_prompt=negative_prompt if negative_prompt.strip() else None,
|
| 314 |
+
num_frames=num_frames,
|
| 315 |
+
height=height,
|
| 316 |
+
width=width,
|
| 317 |
+
num_inference_steps=num_inference_steps,
|
| 318 |
+
guidance_scale=guidance_scale,
|
| 319 |
+
generator=generator
|
| 320 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 321 |
|
| 322 |
end_time = time.time()
|
| 323 |
generation_time = end_time - start_time
|
| 324 |
|
| 325 |
+
# Export video
|
| 326 |
+
video_frames = result.frames[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 327 |
|
|
|
|
| 328 |
with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as tmp_file:
|
| 329 |
from diffusers.utils import export_to_video
|
| 330 |
+
export_to_video(video_frames, tmp_file.name, fps=8)
|
| 331 |
video_path = tmp_file.name
|
| 332 |
|
| 333 |
+
# Clear memory
|
| 334 |
+
if HAS_CUDA:
|
| 335 |
+
torch.cuda.empty_cache()
|
| 336 |
+
gc.collect()
|
| 337 |
|
| 338 |
+
success_msg = f"""✅ **H200 Video Generated!**
|
| 339 |
|
| 340 |
+
🤖 **Model:** {MODEL_INFO['name']}
|
| 341 |
📝 **Prompt:** {prompt}
|
| 342 |
+
🎬 **Frames:** {num_frames}
|
| 343 |
📐 **Resolution:** {width}x{height}
|
| 344 |
⚙️ **Inference Steps:** {num_inference_steps}
|
| 345 |
+
🎯 **Guidance:** {guidance_scale}
|
| 346 |
🎲 **Seed:** {seed}
|
| 347 |
+
⏱️ **Time:** {generation_time:.1f}s
|
| 348 |
🖥️ **Device:** H200 CUDA
|
| 349 |
+
💡 **Notes:** {MODEL_INFO['description']}"""
|
|
|
|
| 350 |
|
| 351 |
return video_path, success_msg
|
| 352 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 353 |
except Exception as e:
|
| 354 |
if HAS_CUDA:
|
| 355 |
torch.cuda.empty_cache()
|
| 356 |
gc.collect()
|
| 357 |
return None, f"❌ Generation failed: {str(e)}"
|
| 358 |
|
| 359 |
+
def get_loading_logs():
|
| 360 |
+
"""Get detailed loading logs"""
|
| 361 |
+
global LOADING_LOGS
|
|
|
|
| 362 |
|
| 363 |
+
if not LOADING_LOGS:
|
| 364 |
+
return "No loading attempts yet. Click 'Load Model' to start."
|
| 365 |
+
|
| 366 |
+
return "\n".join(LOADING_LOGS)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 367 |
|
| 368 |
+
def get_system_diagnostic():
|
| 369 |
+
"""Comprehensive system diagnostic"""
|
|
|
|
|
|
|
| 370 |
|
| 371 |
+
diagnostic = []
|
|
|
|
|
|
|
| 372 |
|
| 373 |
+
# Environment check
|
| 374 |
+
diagnostic.append("## 🖥️ H200 System Diagnostic")
|
| 375 |
+
diagnostic.append(f"- ZeroGPU: {'✅' if IS_ZERO_GPU else '❌'}")
|
| 376 |
+
diagnostic.append(f"- HF Spaces: {'✅' if IS_SPACES else '❌'}")
|
| 377 |
+
diagnostic.append(f"- CUDA: {'✅' if HAS_CUDA else '❌'}")
|
| 378 |
+
|
| 379 |
+
# GPU info
|
| 380 |
+
if HAS_CUDA:
|
| 381 |
+
try:
|
| 382 |
+
gpu_name = torch.cuda.get_device_name(0)
|
| 383 |
+
total_memory = torch.cuda.get_device_properties(0).total_memory / (1024**3)
|
| 384 |
+
diagnostic.append(f"- GPU: {gpu_name}")
|
| 385 |
+
diagnostic.append(f"- Memory: {total_memory:.1f} GB")
|
| 386 |
+
except Exception as e:
|
| 387 |
+
diagnostic.append(f"- GPU Error: {e}")
|
| 388 |
+
|
| 389 |
+
# Package versions
|
| 390 |
+
try:
|
| 391 |
+
import diffusers
|
| 392 |
+
diagnostic.append(f"- Diffusers: {diffusers.__version__}")
|
| 393 |
+
except ImportError:
|
| 394 |
+
diagnostic.append("- Diffusers: ❌ Not installed")
|
| 395 |
+
|
| 396 |
+
try:
|
| 397 |
+
import transformers
|
| 398 |
+
diagnostic.append(f"- Transformers: {transformers.__version__}")
|
| 399 |
+
except ImportError:
|
| 400 |
+
diagnostic.append("- Transformers: ❌ Not installed")
|
| 401 |
+
|
| 402 |
+
# Available pipelines
|
| 403 |
+
available = check_available_pipelines()
|
| 404 |
+
diagnostic.append("\n## 📋 Available Pipelines")
|
| 405 |
+
for pipeline, status in available.items():
|
| 406 |
+
diagnostic.append(f"- {pipeline}: {'✅' if status else '❌'}")
|
| 407 |
+
|
| 408 |
+
# Model status
|
| 409 |
+
diagnostic.append("\n## 🤖 Model Status")
|
| 410 |
+
if MODEL is not None:
|
| 411 |
+
diagnostic.append(f"- Loaded: ✅ {MODEL_INFO['name']}")
|
| 412 |
+
diagnostic.append(f"- Resolution: {MODEL_INFO['resolution']}")
|
| 413 |
+
diagnostic.append(f"- Max Frames: {MODEL_INFO['max_frames']}")
|
| 414 |
+
else:
|
| 415 |
+
diagnostic.append("- Loaded: ❌ No model loaded")
|
| 416 |
+
|
| 417 |
+
return "\n".join(diagnostic)
|
| 418 |
|
| 419 |
+
def force_load_model():
|
| 420 |
+
"""Force reload model"""
|
| 421 |
+
global MODEL, MODEL_INFO
|
| 422 |
+
MODEL = None
|
| 423 |
+
MODEL_INFO = None
|
| 424 |
+
|
| 425 |
+
success = load_any_working_model()
|
| 426 |
+
return f"🔄 Force reload: {'✅ Success' if success else '❌ Failed'}"
|
| 427 |
|
| 428 |
+
# Create diagnostic interface
|
| 429 |
+
with gr.Blocks(title="H200 Video Generator - Debug Mode", theme=gr.themes.Soft()) as demo:
|
| 430 |
|
| 431 |
gr.Markdown("""
|
| 432 |
+
# 🔧 H200 Video Generator - Debug Mode
|
|
|
|
|
|
|
| 433 |
|
| 434 |
+
**Systematic model loading with full diagnostics**
|
| 435 |
""")
|
| 436 |
|
| 437 |
+
with gr.Tab("🎥 Generate Video"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 438 |
with gr.Row():
|
| 439 |
with gr.Column(scale=1):
|
| 440 |
prompt_input = gr.Textbox(
|
| 441 |
+
label="📝 Video Prompt",
|
| 442 |
+
placeholder="A cat playing with a ball in a sunny garden...",
|
| 443 |
+
lines=3
|
|
|
|
| 444 |
)
|
| 445 |
|
| 446 |
negative_prompt_input = gr.Textbox(
|
| 447 |
label="🚫 Negative Prompt",
|
| 448 |
+
placeholder="blurry, low quality, distorted...",
|
| 449 |
lines=2
|
| 450 |
)
|
| 451 |
|
| 452 |
+
with gr.Row():
|
| 453 |
+
num_frames = gr.Slider(8, 50, value=16, step=1, label="🎬 Frames")
|
| 454 |
+
num_steps = gr.Slider(10, 50, value=20, step=1, label="⚙️ Steps")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 455 |
|
| 456 |
+
with gr.Row():
|
| 457 |
+
guidance_scale = gr.Slider(1.0, 15.0, value=7.5, step=0.5, label="🎯 Guidance")
|
| 458 |
+
seed = gr.Number(value=-1, precision=0, label="🎲 Seed")
|
| 459 |
|
| 460 |
+
generate_btn = gr.Button("🚀 Generate Video", variant="primary", size="lg")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 461 |
|
| 462 |
with gr.Column(scale=1):
|
| 463 |
+
video_output = gr.Video(label="🎥 Generated Video", height=400)
|
| 464 |
+
result_text = gr.Textbox(label="📋 Results", lines=8, show_copy_button=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 465 |
|
|
|
|
| 466 |
generate_btn.click(
|
| 467 |
fn=generate_video,
|
| 468 |
+
inputs=[prompt_input, negative_prompt_input, num_frames, num_steps, guidance_scale, seed],
|
|
|
|
|
|
|
|
|
|
| 469 |
outputs=[video_output, result_text]
|
| 470 |
)
|
| 471 |
|
| 472 |
+
# Simple examples
|
| 473 |
gr.Examples(
|
| 474 |
examples=[
|
| 475 |
+
["A peaceful cat sleeping in a sunny garden", "", 16, 20, 7.5, 42],
|
| 476 |
+
["Ocean waves gently washing the shore", "blurry", 20, 25, 8.0, 123],
|
| 477 |
+
["A butterfly landing on a flower", "", 16, 20, 7.0, 456]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 478 |
],
|
| 479 |
+
inputs=[prompt_input, negative_prompt_input, num_frames, num_steps, guidance_scale, seed]
|
| 480 |
)
|
| 481 |
|
| 482 |
+
with gr.Tab("🔧 Debug & Diagnostics"):
|
| 483 |
with gr.Row():
|
| 484 |
+
diagnostic_btn = gr.Button("🔍 System Diagnostic", variant="secondary")
|
| 485 |
+
logs_btn = gr.Button("📋 Loading Logs", variant="secondary")
|
| 486 |
+
reload_btn = gr.Button("🔄 Force Reload Model", variant="secondary")
|
| 487 |
|
| 488 |
+
diagnostic_output = gr.Markdown()
|
| 489 |
+
logs_output = gr.Textbox(label="Loading Logs", lines=15, show_copy_button=True)
|
| 490 |
+
reload_output = gr.Textbox(label="Reload Result", lines=2)
|
| 491 |
|
| 492 |
+
diagnostic_btn.click(fn=get_system_diagnostic, outputs=diagnostic_output)
|
| 493 |
+
logs_btn.click(fn=get_loading_logs, outputs=logs_output)
|
| 494 |
+
reload_btn.click(fn=force_load_model, outputs=reload_output)
|
| 495 |
|
| 496 |
+
# Auto-load diagnostic
|
| 497 |
+
demo.load(fn=get_system_diagnostic, outputs=diagnostic_output)
|
| 498 |
|
| 499 |
+
with gr.Tab("💡 Troubleshooting"):
|
| 500 |
gr.Markdown("""
|
| 501 |
+
## 🔧 H200 Troubleshooting Guide
|
| 502 |
+
|
| 503 |
+
### 🚨 Common Issues & Solutions:
|
| 504 |
+
|
| 505 |
+
**❌ "All premium models failed to load"**
|
| 506 |
+
|
| 507 |
+
**Possible Causes:**
|
| 508 |
+
1. **Pipeline not available:** LTXVideoPipeline, HunyuanVideoPipeline may not be in stable diffusers
|
| 509 |
+
2. **Model access:** Some models may be gated or require authentication
|
| 510 |
+
3. **Memory issues:** Even H200 can have limits during loading
|
| 511 |
+
4. **Network timeouts:** Large model downloads can timeout
|
| 512 |
+
|
| 513 |
+
**Solutions:**
|
| 514 |
+
1. **Check System Diagnostic tab** - see what pipelines are available
|
| 515 |
+
2. **View Loading Logs** - detailed error messages
|
| 516 |
+
3. **Force Reload Model** - retry with fresh state
|
| 517 |
+
4. **Wait and retry** - sometimes it's just a temporary issue
|
| 518 |
+
|
| 519 |
+
### 🎯 Step-by-Step Debugging:
|
| 520 |
+
|
| 521 |
+
**Step 1: Check Environment**
|
| 522 |
+
- Click "System Diagnostic"
|
| 523 |
+
- Verify H200 GPU is detected
|
| 524 |
+
- Check if diffusers/transformers are installed
|
| 525 |
+
|
| 526 |
+
**Step 2: Check Available Pipelines**
|
| 527 |
+
- Look for ✅ next to DiffusionPipeline (minimum required)
|
| 528 |
+
- LTXVideoPipeline/HunyuanVideoPipeline may be ❌ (that's ok)
|
| 529 |
+
|
| 530 |
+
**Step 3: Check Loading Logs**
|
| 531 |
+
- Click "Loading Logs" to see detailed attempt logs
|
| 532 |
+
- Look for specific error messages
|
| 533 |
+
- Note which models were tried
|
| 534 |
+
|
| 535 |
+
**Step 4: Force Reload**
|
| 536 |
+
- Click "Force Reload Model" if needed
|
| 537 |
+
- This clears cache and retries
|
| 538 |
+
|
| 539 |
+
### 🔄 Fallback Strategy:
|
| 540 |
+
|
| 541 |
+
This app tries models in this order:
|
| 542 |
+
1. **LTX-Video** (premium)
|
| 543 |
+
2. **HunyuanVideo** (premium)
|
| 544 |
+
3. **Zeroscope V2** (reliable fallback)
|
| 545 |
+
4. **ModelScope T2V** (backup)
|
| 546 |
+
5. **AliVilab T2V** (final fallback)
|
| 547 |
+
|
| 548 |
+
At least one should work!
|
| 549 |
+
|
| 550 |
+
### 💡 Tips:
|
| 551 |
+
- First run always takes longer (model download)
|
| 552 |
+
- H200 has plenty of memory, so memory errors are rare
|
| 553 |
+
- Check HuggingFace status if all models fail
|
| 554 |
+
- Some models may need authentication tokens
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 555 |
""")
|
| 556 |
|
|
|
|
| 557 |
if __name__ == "__main__":
|
| 558 |
+
demo.queue(max_size=5)
|
| 559 |
demo.launch(
|
| 560 |
share=False,
|
| 561 |
server_name="0.0.0.0",
|
| 562 |
server_port=7860,
|
| 563 |
+
show_error=True
|
|
|
|
| 564 |
)
|