Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -227,20 +227,20 @@ def generate_storyboard_with_llm(user_prompt: str, n_shots: int, default_fps: in
|
|
| 227 |
# =========================
|
| 228 |
# IMAGE GEN (ZeroGPU) — SD1.5 text2img + img2img chaining
|
| 229 |
# =========================
|
| 230 |
-
|
| 231 |
from diffusers import StableDiffusionPipeline, StableDiffusionImg2ImgPipeline
|
| 232 |
|
| 233 |
-
SD_MODEL = os.getenv("SD_MODEL", "
|
| 234 |
_sd_t2i = None
|
| 235 |
_sd_i2i = None
|
| 236 |
|
| 237 |
def _lazy_sd_pipes():
|
| 238 |
"""
|
| 239 |
-
Load SD once
|
| 240 |
-
-
|
| 241 |
-
-
|
| 242 |
-
-
|
| 243 |
-
-
|
| 244 |
"""
|
| 245 |
global _sd_t2i, _sd_i2i
|
| 246 |
if _sd_t2i is not None and _sd_i2i is not None:
|
|
@@ -248,22 +248,20 @@ def _lazy_sd_pipes():
|
|
| 248 |
|
| 249 |
use_cuda = torch.cuda.is_available()
|
| 250 |
dtype = torch.float16 if use_cuda else torch.float32
|
|
|
|
| 251 |
|
| 252 |
-
# Important: torch_dtype + low_cpu_mem_usage=False to avoid offload_state_dict
|
| 253 |
_sd_t2i = StableDiffusionPipeline.from_pretrained(
|
| 254 |
SD_MODEL,
|
| 255 |
-
torch_dtype=dtype,
|
| 256 |
-
safety_checker=None,
|
| 257 |
feature_extractor=None,
|
| 258 |
use_safetensors=True,
|
| 259 |
-
low_cpu_mem_usage=False,
|
| 260 |
-
|
| 261 |
)
|
| 262 |
-
|
| 263 |
if use_cuda:
|
| 264 |
_sd_t2i = _sd_t2i.to("cuda")
|
| 265 |
|
| 266 |
-
# Build img2img from the same components (avoid another from_pretrained call)
|
| 267 |
_sd_i2i = StableDiffusionImg2ImgPipeline(
|
| 268 |
vae=_sd_t2i.vae,
|
| 269 |
text_encoder=_sd_t2i.text_encoder,
|
|
|
|
| 227 |
# =========================
|
| 228 |
# IMAGE GEN (ZeroGPU) — SD1.5 text2img + img2img chaining
|
| 229 |
# =========================
|
| 230 |
+
|
| 231 |
from diffusers import StableDiffusionPipeline, StableDiffusionImg2ImgPipeline
|
| 232 |
|
| 233 |
+
SD_MODEL = os.getenv("SD_MODEL", "stabilityai/sd-turbo")
|
| 234 |
_sd_t2i = None
|
| 235 |
_sd_i2i = None
|
| 236 |
|
| 237 |
def _lazy_sd_pipes():
|
| 238 |
"""
|
| 239 |
+
Load SD once in a version-safe way:
|
| 240 |
+
- torch_dtype (not dtype)
|
| 241 |
+
- low_cpu_mem_usage=False to avoid offload_state_dict kwarg
|
| 242 |
+
- no revision pin (some repos don't have 'fp16' branch)
|
| 243 |
+
- optional HF token if set (for gated models)
|
| 244 |
"""
|
| 245 |
global _sd_t2i, _sd_i2i
|
| 246 |
if _sd_t2i is not None and _sd_i2i is not None:
|
|
|
|
| 248 |
|
| 249 |
use_cuda = torch.cuda.is_available()
|
| 250 |
dtype = torch.float16 if use_cuda else torch.float32
|
| 251 |
+
hf_token = os.getenv("HF_TOKEN", None) # add this in Space Secrets only if needed
|
| 252 |
|
|
|
|
| 253 |
_sd_t2i = StableDiffusionPipeline.from_pretrained(
|
| 254 |
SD_MODEL,
|
| 255 |
+
torch_dtype=dtype,
|
| 256 |
+
safety_checker=None,
|
| 257 |
feature_extractor=None,
|
| 258 |
use_safetensors=True,
|
| 259 |
+
low_cpu_mem_usage=False,
|
| 260 |
+
token=hf_token
|
| 261 |
)
|
|
|
|
| 262 |
if use_cuda:
|
| 263 |
_sd_t2i = _sd_t2i.to("cuda")
|
| 264 |
|
|
|
|
| 265 |
_sd_i2i = StableDiffusionImg2ImgPipeline(
|
| 266 |
vae=_sd_t2i.vae,
|
| 267 |
text_encoder=_sd_t2i.text_encoder,
|