Shalmoni commited on
Commit
ed0a461
·
verified ·
1 Parent(s): f01e490

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -14
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
- # --- replace the whole _lazy_sd_pipes() with this ---
231
  from diffusers import StableDiffusionPipeline, StableDiffusionImg2ImgPipeline
232
 
233
- SD_MODEL = os.getenv("SD_MODEL", "runwayml/stable-diffusion-v1-5")
234
  _sd_t2i = None
235
  _sd_i2i = None
236
 
237
  def _lazy_sd_pipes():
238
  """
239
- Load SD once with settings that avoid the `offload_state_dict` kwarg issue:
240
- - use `torch_dtype` (not `dtype`)
241
- - set `low_cpu_mem_usage=False`
242
- - disable safety checker at load time
243
- - build Img2Img from the already-loaded modules (no second from_pretrained)
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, # <-- correct kwarg
256
- safety_checker=None, # disable safety checker at load
257
  feature_extractor=None,
258
  use_safetensors=True,
259
- low_cpu_mem_usage=False, # <-- critical to prevent passing offload_state_dict
260
- revision="fp16" if use_cuda else None # helps pick fp16 weights on GPU
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,