Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -58,26 +58,67 @@ patch_processor_fast(SiglipProcessor)
|
|
58 |
|
59 |
print("π Loading Cosmos-Predict2 model...")
|
60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
# Load the model at startup
|
62 |
model_id = "nvidia/Cosmos-Predict2-2B-Text2Image"
|
63 |
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
pipe.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
|
80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
|
82 |
# Default negative prompt for better quality
|
83 |
DEFAULT_NEGATIVE_PROMPT = "The video captures a series of frames showing ugly scenes, static with no motion, motion blur, over-saturation, shaky footage, low resolution, grainy texture, pixelated images, poorly lit areas, underexposed and overexposed scenes, poor color balance, washed out colors, choppy sequences, jerky movements, low frame rate, artifacting, color banding, unnatural transitions, outdated special effects, fake elements, unconvincing visuals, poorly edited content, jump cuts, visual noise, and flickering. Overall, the video is of poor quality."
|
@@ -162,7 +203,7 @@ def create_interface():
|
|
162 |
with gr.Blocks(title="Cosmos-Predict2 ZeroGPU", theme=gr.themes.Soft()) as interface:
|
163 |
gr.Markdown("""
|
164 |
# π Cosmos-Predict2 on ZeroGPU
|
165 |
-
**
|
166 |
|
167 |
This Space uses ZeroGPU for efficient GPU allocation. The model is pre-loaded and ready to generate!
|
168 |
""")
|
|
|
58 |
|
59 |
print("π Loading Cosmos-Predict2 model...")
|
60 |
|
61 |
+
# Handle authentication for gated model
|
62 |
+
try:
|
63 |
+
from huggingface_hub import login
|
64 |
+
import os
|
65 |
+
|
66 |
+
# Try to login with token from environment variable
|
67 |
+
hf_token = os.getenv("HF_TOKEN")
|
68 |
+
if hf_token:
|
69 |
+
login(token=hf_token)
|
70 |
+
print("β
Authenticated with Hugging Face")
|
71 |
+
else:
|
72 |
+
print("β οΈ No HF_TOKEN found, trying without authentication...")
|
73 |
+
except Exception as e:
|
74 |
+
print(f"β οΈ Authentication failed: {e}")
|
75 |
+
|
76 |
# Load the model at startup
|
77 |
model_id = "nvidia/Cosmos-Predict2-2B-Text2Image"
|
78 |
|
79 |
+
try:
|
80 |
+
if COSMOS_PIPELINE_AVAILABLE:
|
81 |
+
print("π Loading with Cosmos2TextToImagePipeline...")
|
82 |
+
try:
|
83 |
+
# Try loading with safety checker first
|
84 |
+
pipe = Cosmos2TextToImagePipeline.from_pretrained(
|
85 |
+
model_id,
|
86 |
+
torch_dtype=torch.bfloat16,
|
87 |
+
use_auth_token=True # Use authentication token
|
88 |
+
)
|
89 |
+
except ImportError as e:
|
90 |
+
if "cosmos_guardrail" in str(e):
|
91 |
+
print("β οΈ cosmos_guardrail not available, trying without safety checker...")
|
92 |
+
# Try loading without safety checker
|
93 |
+
pipe = Cosmos2TextToImagePipeline.from_pretrained(
|
94 |
+
model_id,
|
95 |
+
torch_dtype=torch.bfloat16,
|
96 |
+
use_auth_token=True,
|
97 |
+
safety_checker=None,
|
98 |
+
requires_safety_checker=False
|
99 |
+
)
|
100 |
+
else:
|
101 |
+
raise e
|
102 |
+
else:
|
103 |
+
print("π Loading with DiffusionPipeline (trust_remote_code=True)...")
|
104 |
+
pipe = DiffusionPipeline.from_pretrained(
|
105 |
+
model_id,
|
106 |
+
torch_dtype=torch.bfloat16,
|
107 |
+
trust_remote_code=True,
|
108 |
+
use_auth_token=True # Use authentication token
|
109 |
+
)
|
110 |
|
111 |
+
pipe.to("cuda")
|
112 |
+
print("β
Cosmos-Predict2 model loaded successfully!")
|
113 |
+
|
114 |
+
except Exception as e:
|
115 |
+
print(f"β Failed to load Cosmos model: {e}")
|
116 |
+
print("π This is likely due to the model being gated/restricted or missing dependencies")
|
117 |
+
print("π Please check the Setup Guide for authentication instructions")
|
118 |
+
|
119 |
+
# For demo purposes, we could fall back to a different model
|
120 |
+
# But for now, let's just exit gracefully
|
121 |
+
raise e
|
122 |
|
123 |
# Default negative prompt for better quality
|
124 |
DEFAULT_NEGATIVE_PROMPT = "The video captures a series of frames showing ugly scenes, static with no motion, motion blur, over-saturation, shaky footage, low resolution, grainy texture, pixelated images, poorly lit areas, underexposed and overexposed scenes, poor color balance, washed out colors, choppy sequences, jerky movements, low frame rate, artifacting, color banding, unnatural transitions, outdated special effects, fake elements, unconvincing visuals, poorly edited content, jump cuts, visual noise, and flickering. Overall, the video is of poor quality."
|
|
|
203 |
with gr.Blocks(title="Cosmos-Predict2 ZeroGPU", theme=gr.themes.Soft()) as interface:
|
204 |
gr.Markdown("""
|
205 |
# π Cosmos-Predict2 on ZeroGPU
|
206 |
+
**High-resolution generation β’ Fast inference**
|
207 |
|
208 |
This Space uses ZeroGPU for efficient GPU allocation. The model is pre-loaded and ready to generate!
|
209 |
""")
|