ozilion commited on
Commit
7a8e438
Β·
verified Β·
1 Parent(s): 7358182

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +402 -541
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 support
11
  try:
12
  import spaces
13
  SPACES_AVAILABLE = True
14
- print("βœ… Spaces library loaded - H200 detected!")
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"πŸš€ H200 Environment: ZeroGPU={IS_ZERO_GPU}, Spaces={IS_SPACES}, CUDA={HAS_CUDA}")
29
 
30
- # Premium models optimized for H200's massive memory
31
- PREMIUM_MODELS = {
32
- "ltx": {
33
- "id": "Lightricks/LTX-Video",
34
- "name": "LTX-Video",
35
- "pipeline_class": "LTXVideoPipeline",
36
- "resolution_options": [(512, 512), (768, 768), (1024, 1024), (1280, 720), (1920, 1080)],
37
- "max_frames": 161, # H200 can handle more frames
38
- "dtype": torch.bfloat16,
39
- "priority": 1,
40
- "description": "Lightricks' flagship model - professional quality"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  },
42
- "hunyuan": {
43
- "id": "tencent/HunyuanVideo",
44
- "name": "HunyuanVideo",
45
- "pipeline_class": "HunyuanVideoPipeline",
46
- "resolution_options": [(512, 512), (768, 768), (1024, 1024), (1280, 720)],
47
- "max_frames": 129, # Extended for H200
48
- "dtype": torch.bfloat16,
49
- "priority": 2,
50
- "description": "Tencent's advanced video model with superior motion"
51
  },
52
- "wan": {
53
- "id": "wangfuyun/AnimateLCM",
54
- "name": "AnimateLCM",
55
- "pipeline_class": "DiffusionPipeline",
56
- "resolution_options": [(512, 512), (768, 768), (1024, 1024)],
57
- "max_frames": 64,
58
  "dtype": torch.float16,
59
- "priority": 3,
60
- "description": "Fast, high-quality animation model"
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  },
62
- "cogvideo": {
63
- "id": "THUDM/CogVideoX-5b",
64
- "name": "CogVideoX-5B",
65
- "pipeline_class": "CogVideoXPipeline",
66
- "resolution_options": [(720, 480), (1280, 720)],
67
- "max_frames": 49,
 
68
  "dtype": torch.bfloat16,
69
- "priority": 4,
70
- "description": "CogVideo's 5B parameter model"
71
  }
72
- }
73
 
74
  # Global variables
75
  MODEL = None
76
  MODEL_INFO = None
77
- LOADING_ERROR = None
78
 
79
- def get_gpu_memory():
80
- """Get H200 GPU memory info"""
81
- if HAS_CUDA:
82
- try:
83
- total_memory = torch.cuda.get_device_properties(0).total_memory / (1024**3)
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 load_premium_model():
92
- """Load first available premium model with H200 optimizations"""
93
- global MODEL, MODEL_INFO, LOADING_ERROR
94
 
95
  if MODEL is not None:
96
  return True
97
 
98
- # Sort models by priority
99
- sorted_models = sorted(PREMIUM_MODELS.items(), key=lambda x: x[1]["priority"])
100
 
101
- for key, info in sorted_models:
102
- try:
103
- print(f"πŸ”„ Loading {info['name']} on H200...")
104
- total_mem, allocated, cached = get_gpu_memory()
105
- print(f"πŸ’Ύ GPU Memory: {total_mem:.1f}GB total, {allocated:.1f}GB allocated")
106
-
107
- from diffusers import DiffusionPipeline
108
-
109
- # Try specific pipeline class first
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  try:
111
- if info["pipeline_class"] == "LTXVideoPipeline":
 
 
112
  from diffusers import LTXVideoPipeline
113
  pipe = LTXVideoPipeline.from_pretrained(
114
- info["id"],
115
- torch_dtype=info["dtype"],
116
  use_safetensors=True,
117
  variant="fp16"
118
  )
119
- elif info["pipeline_class"] == "HunyuanVideoPipeline":
120
- from diffusers import HunyuanVideoPipeline
121
  pipe = HunyuanVideoPipeline.from_pretrained(
122
- info["id"],
123
- torch_dtype=info["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
- info["id"],
138
- torch_dtype=info["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
- # Enable all optimizations but keep model in VRAM
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
- # Enable xformers if available for extra speed
169
- try:
170
- pipe.enable_xformers_memory_efficient_attention()
171
- print("πŸš€ XFormers acceleration enabled")
172
- except:
173
- print("⚠️ XFormers not available")
174
-
175
- MODEL = pipe
176
- MODEL_INFO = info
177
-
178
- final_mem = torch.cuda.memory_allocated(0) / (1024**3)
179
- print(f"βœ… {info['name']} loaded successfully! Memory used: {final_mem:.1f}GB")
180
- return True
181
-
182
- except Exception as e:
183
- print(f"❌ Failed to load {info['name']}: {e}")
184
- # Clear memory before trying next model
185
- if HAS_CUDA:
186
- torch.cuda.empty_cache()
187
- gc.collect()
188
- continue
189
-
190
- LOADING_ERROR = "All premium models failed to load"
191
- return False
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192
 
193
- @spaces.GPU(duration=300) if SPACES_AVAILABLE else lambda x: x # 5 minutes for H200
194
  def generate_video(
195
  prompt: str,
196
  negative_prompt: str = "",
197
- num_frames: int = 49,
198
- resolution: str = "1024x1024",
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 premium video with H200 power"""
205
 
206
- global MODEL, MODEL_INFO, LOADING_ERROR
207
 
208
  # Load model if needed
209
- if not load_premium_model():
210
- return None, f"❌ No premium models available: {LOADING_ERROR}"
211
 
212
  # Input validation
213
  if not prompt.strip():
214
  return None, "❌ Please enter a valid prompt."
215
 
216
- if len(prompt) > 1000: # H200 can handle longer prompts
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
- num_frames = min(max(num_frames, 8), max_frames)
228
 
229
- # Check if resolution is supported
230
- if (width, height) not in MODEL_INFO["resolution_options"]:
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 management - we have tons of memory!
238
- start_memory = torch.cuda.memory_allocated(0) / (1024**3) if HAS_CUDA else 0
 
 
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']} - '{prompt[:70]}...'")
248
- print(f"πŸ“ {width}x{height}, {num_frames} frames, {num_inference_steps} steps")
249
  start_time = time.time()
250
 
251
- # Generate with H200's full power
252
  with torch.autocast(device, dtype=MODEL_INFO["dtype"]):
253
- generation_kwargs = {
254
- "prompt": prompt,
255
- "num_frames": num_frames,
256
- "height": height,
257
- "width": width,
258
- "num_inference_steps": num_inference_steps,
259
- "guidance_scale": guidance_scale,
260
- "generator": generator
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
- # Extract video frames
279
- if hasattr(result, 'frames'):
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=fps)
290
  video_path = tmp_file.name
291
 
292
- # Memory stats
293
- end_memory = torch.cuda.memory_allocated(0) / (1024**3) if HAS_CUDA else 0
294
- memory_used = end_memory - start_memory
 
295
 
296
- success_msg = f"""βœ… **H200 Premium Video Generated!**
297
 
298
- πŸš€ **Model:** {MODEL_INFO['name']}
299
  πŸ“ **Prompt:** {prompt}
300
- 🎬 **Frames:** {num_frames} @ {fps} FPS
301
  πŸ“ **Resolution:** {width}x{height}
302
  βš™οΈ **Inference Steps:** {num_inference_steps}
303
- 🎯 **Guidance Scale:** {guidance_scale}
304
  🎲 **Seed:** {seed}
305
- ⏱️ **Generation Time:** {generation_time:.1f}s
306
  πŸ–₯️ **Device:** H200 CUDA
307
- πŸ’Ύ **Memory Used:** {memory_used:.1f}GB
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 get_h200_status():
325
- """Get H200 specific status"""
326
- if not HAS_CUDA:
327
- return "❌ CUDA not available"
328
 
329
- try:
330
- total_mem, allocated, cached = get_gpu_memory()
331
- gpu_name = torch.cuda.get_device_name(0)
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 suggest_h200_settings():
361
- """Suggest optimal settings for H200"""
362
- if MODEL is None:
363
- return "Load a model first to get personalized recommendations"
364
 
365
- model_name = MODEL_INFO['name']
366
- max_frames = MODEL_INFO['max_frames']
367
- max_res = MODEL_INFO['resolution_options'][-1]
368
 
369
- return f"""## 🎯 H200 Optimized Settings for {model_name}
370
-
371
- **πŸš€ Maximum Quality (Recommended):**
372
- - Resolution: {max_res[0]}x{max_res[1]}
373
- - Frames: {max_frames}
374
- - Inference Steps: 50
375
- - Expected Time: 3-5 minutes
376
-
377
- **βš–οΈ Balanced (Fast & Good):**
378
- - Resolution: 1024x1024
379
- - Frames: {max_frames//2}
380
- - Inference Steps: 30
381
- - Expected Time: 1-2 minutes
382
-
383
- **⚑ Speed Test:**
384
- - Resolution: 512x512
385
- - Frames: 25
386
- - Inference Steps: 20
387
- - Expected Time: 30-60 seconds
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
388
 
389
- **πŸ’‘ H200 Tips:**
390
- - Use longer prompts - H200 can handle complexity
391
- - Try higher inference steps (30-50) for maximum quality
392
- - Experiment with longer videos (40+ frames)
393
- - Multiple generations won't cause memory issues"""
 
 
 
394
 
395
- # Create H200-optimized interface
396
- with gr.Blocks(title="H200 Premium Video Generator", theme=gr.themes.Glass()) as demo:
397
 
398
  gr.Markdown("""
399
- # πŸš€ H200 Premium Video Generator
400
-
401
- **Powered by NVIDIA H200** β€’ **141GB Memory** β€’ **Premium Models Only**
402
 
403
- *LTX-Video β€’ HunyuanVideo β€’ CogVideoX-5B β€’ AnimateLCM*
404
  """)
405
 
406
- # H200 status bar
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="πŸ“ Detailed Video Prompt (H200 can handle complexity!)",
419
- placeholder="A breathtaking aerial view of a majestic golden eagle soaring through dramatic mountain peaks during a spectacular sunrise, with volumetric lighting piercing through morning mist, cinematic composition with dynamic camera movement following the eagle's graceful flight path, professional cinematography with shallow depth of field and warm golden color grading, 8K quality with film grain texture...",
420
- lines=5,
421
- max_lines=8
422
  )
423
 
424
  negative_prompt_input = gr.Textbox(
425
  label="🚫 Negative Prompt",
426
- placeholder="blurry, low quality, distorted, pixelated, watermark, text, signature, amateur, static, boring, unnatural motion...",
427
  lines=2
428
  )
429
 
430
- with gr.Accordion("πŸš€ H200 Advanced Settings", open=True):
431
- with gr.Row():
432
- num_frames = gr.Slider(
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.Markdown("""
485
- **⏱️ H200 Generation:** 1-5 minutes depending on settings
 
486
 
487
- **πŸ”₯ H200 Power:**
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
- label="πŸŽ₯ H200 Generated Premium Video",
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
- # H200-optimized examples
517
  gr.Examples(
518
  examples=[
519
- [
520
- "A majestic golden eagle soaring through misty mountain peaks at sunrise, cinematic aerial cinematography with dramatic volumetric lighting, professional color grading with warm golden tones, shallow depth of field, dynamic camera movement tracking the eagle's flight, 8K quality with film grain",
521
- "blurry, low quality, pixelated, static, amateur, watermark, text",
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, resolution, num_steps, guidance_scale, seed, fps]
541
  )
542
 
543
- with gr.Tab("πŸ’Ύ H200 Status"):
544
  with gr.Row():
545
- status_btn = gr.Button("πŸ” Check H200 Status", variant="secondary")
546
- settings_btn = gr.Button("🎯 Get Optimal Settings", variant="secondary")
 
547
 
548
- status_output = gr.Markdown()
549
- settings_output = gr.Markdown()
 
550
 
551
- status_btn.click(fn=get_h200_status, outputs=status_output)
552
- settings_btn.click(fn=suggest_h200_settings, outputs=settings_output)
 
553
 
554
- # Auto-load status
555
- demo.load(fn=get_h200_status, outputs=status_output)
556
 
557
- with gr.Tab("🎬 H200 Master Guide"):
558
  gr.Markdown("""
559
- ## πŸš€ H200 Video Generation Mastery
560
-
561
- ### πŸ’Ž Why H200 is Game-Changing:
562
-
563
- **πŸ”₯ Raw Power:**
564
- - **141GB HBM3 Memory** (vs 80GB A100)
565
- - **4.8TB/s Bandwidth** (vs 3.35TB/s A100)
566
- - **67% More Memory** for bigger models & longer videos
567
- - **No Memory Swapping** = Consistent performance
568
-
569
- ### 🎯 H200-Optimized Strategies:
570
-
571
- **🎬 Long-Form Content (H200 Specialty):**
572
- - Frames: 80-161 (2-20 second videos)
573
- - Resolution: 1280x720 or 1024x1024
574
- - Steps: 40-50 for cinematic quality
575
- - Perfect for: Storytelling, commercials, art pieces
576
-
577
- **πŸ–ΌοΈ Ultra High-Res (H200 Advantage):**
578
- - Resolution: 1920x1080 (if model supports)
579
- - Frames: 25-49 (manageable length)
580
- - Steps: 30-40
581
- - Perfect for: Wallpapers, presentations, demos
582
-
583
- **⚑ Rapid Prototyping:**
584
- - Multiple quick generations to test ideas
585
- - 512x512, 25 frames, 20 steps
586
- - Iterate quickly, then scale up
587
-
588
- ### ✍️ Advanced Prompt Engineering for H200:
589
-
590
- **Complex Scene Composition:**
591
- ```
592
- [Main Subject] + [Detailed Action] + [Environment Description] +
593
- [Camera Work] + [Lighting] + [Color Grading] + [Technical Quality]
594
- ```
595
-
596
- **Example Structure:**
597
- - **Subject:** "A majestic red dragon"
598
- - **Action:** "gracefully flying through ancient mountain peaks"
599
- - **Environment:** "shrouded in mystical fog with ancient ruins visible below"
600
- - **Camera:** "cinematic aerial tracking shot with dynamic movement"
601
- - **Lighting:** "golden hour lighting with volumetric rays piercing the mist"
602
- - **Grading:** "warm color palette with high contrast and film grain"
603
- - **Quality:** "8K cinematography with shallow depth of field"
604
-
605
- ### 🎨 Style Modifiers for Premium Results:
606
-
607
- **Cinematic Styles:**
608
- - "Christopher Nolan cinematography"
609
- - "Blade Runner 2049 aesthetic"
610
- - "Studio Ghibli animation style"
611
- - "BBC Planet Earth documentary style"
612
- - "Marvel movie action sequence"
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=3) # Smaller queue for premium H200 generations
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
  )