TheAwakenOne commited on
Commit
f726970
Β·
verified Β·
1 Parent(s): 657b503

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -5
app.py CHANGED
@@ -16,12 +16,21 @@ subprocess.run(
16
  import gradio as gr
17
  import spaces
18
  import torch
19
- from diffusers import Cosmos2TextToImagePipeline
20
  from transformers import AutoModelForCausalLM, SiglipProcessor
21
  import random
22
  import gc
23
  import warnings
24
 
 
 
 
 
 
 
 
 
 
 
25
  # Suppress warnings for cleaner output
26
  warnings.filterwarnings("ignore", category=UserWarning)
27
  warnings.filterwarnings("ignore", category=FutureWarning)
@@ -51,10 +60,21 @@ print("🌌 Loading Cosmos-Predict2 model...")
51
 
52
  # Load the model at startup
53
  model_id = "nvidia/Cosmos-Predict2-2B-Text2Image"
54
- pipe = Cosmos2TextToImagePipeline.from_pretrained(
55
- model_id,
56
- torch_dtype=torch.bfloat16
57
- )
 
 
 
 
 
 
 
 
 
 
 
58
  pipe.to("cuda")
59
 
60
  print("βœ… Cosmos-Predict2 model loaded successfully!")
 
16
  import gradio as gr
17
  import spaces
18
  import torch
 
19
  from transformers import AutoModelForCausalLM, SiglipProcessor
20
  import random
21
  import gc
22
  import warnings
23
 
24
+ # Try to import Cosmos-specific pipeline, fall back to generic if not available
25
+ try:
26
+ from diffusers import Cosmos2TextToImagePipeline
27
+ COSMOS_PIPELINE_AVAILABLE = True
28
+ print("βœ… Cosmos2TextToImagePipeline available")
29
+ except ImportError:
30
+ from diffusers import DiffusionPipeline
31
+ COSMOS_PIPELINE_AVAILABLE = False
32
+ print("⚠️ Cosmos2TextToImagePipeline not available, using DiffusionPipeline with trust_remote_code")
33
+
34
  # Suppress warnings for cleaner output
35
  warnings.filterwarnings("ignore", category=UserWarning)
36
  warnings.filterwarnings("ignore", category=FutureWarning)
 
60
 
61
  # Load the model at startup
62
  model_id = "nvidia/Cosmos-Predict2-2B-Text2Image"
63
+
64
+ if COSMOS_PIPELINE_AVAILABLE:
65
+ print("πŸ”„ Loading with Cosmos2TextToImagePipeline...")
66
+ pipe = Cosmos2TextToImagePipeline.from_pretrained(
67
+ model_id,
68
+ torch_dtype=torch.bfloat16
69
+ )
70
+ else:
71
+ print("πŸ”„ Loading with DiffusionPipeline (trust_remote_code=True)...")
72
+ pipe = DiffusionPipeline.from_pretrained(
73
+ model_id,
74
+ torch_dtype=torch.bfloat16,
75
+ trust_remote_code=True
76
+ )
77
+
78
  pipe.to("cuda")
79
 
80
  print("βœ… Cosmos-Predict2 model loaded successfully!")