Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
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 |
-
|
55 |
-
|
56 |
-
|
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!")
|