artificialguybr commited on
Commit
a3cce32
·
1 Parent(s): e05a536

Fix: Resolve ValueError and GatedRepoError issues

Browse files

- Fix ValueError in selected_payload: return 10 values (was 9) when selected_repo is None
- Add HF_TOKEN authentication for gated models (FLUX, etc.)
- Pass token to DiffusionPipeline.from_pretrained() and load_lora_weights()

Files changed (1) hide show
  1. app.py +10 -1
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import hashlib
2
  import inspect
3
  import json
 
4
  from pathlib import Path
5
  from typing import Any
6
 
@@ -27,6 +28,7 @@ COVER_CACHE_DIR = Path("images/auto-covers")
27
  COVER_CACHE_DIR.mkdir(parents=True, exist_ok=True)
28
 
29
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
 
30
  DEFAULT_NEGATIVE = (
31
  "low quality, bad anatomy, bad hands, text, watermark, blurry, jpeg artifacts"
32
  )
@@ -196,6 +198,7 @@ def selected_payload(selected_repo: str):
196
  gr.update(),
197
  gr.update(),
198
  gr.update(),
 
199
  gr.update(value="Auto", interactive=False),
200
  gr.update(value=1.0),
201
  )
@@ -308,7 +311,11 @@ def load_pipeline(base_model: str, family: str) -> DiffusionPipeline:
308
  torch.cuda.empty_cache()
309
 
310
  dtype = pick_dtype_for_family(family)
311
- pipe = DiffusionPipeline.from_pretrained(base_model, torch_dtype=dtype)
 
 
 
 
312
 
313
  if DEVICE == "cuda":
314
  pipe = pipe.to("cuda")
@@ -392,6 +399,8 @@ def run_lora(
392
  weight_name = (selected.get("weight_name") or "").strip()
393
  if weight_name:
394
  load_kwargs["weight_name"] = weight_name
 
 
395
  pipe.load_lora_weights(selected_repo, **load_kwargs)
396
  CURRENT_LOADED_REPO = selected_repo
397
 
 
1
  import hashlib
2
  import inspect
3
  import json
4
+ import os
5
  from pathlib import Path
6
  from typing import Any
7
 
 
28
  COVER_CACHE_DIR.mkdir(parents=True, exist_ok=True)
29
 
30
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
31
+ HF_TOKEN = os.environ.get("HF_TOKEN")
32
  DEFAULT_NEGATIVE = (
33
  "low quality, bad anatomy, bad hands, text, watermark, blurry, jpeg artifacts"
34
  )
 
198
  gr.update(),
199
  gr.update(),
200
  gr.update(),
201
+ gr.update(),
202
  gr.update(value="Auto", interactive=False),
203
  gr.update(value=1.0),
204
  )
 
311
  torch.cuda.empty_cache()
312
 
313
  dtype = pick_dtype_for_family(family)
314
+ pipe = DiffusionPipeline.from_pretrained(
315
+ base_model,
316
+ torch_dtype=dtype,
317
+ token=HF_TOKEN,
318
+ )
319
 
320
  if DEVICE == "cuda":
321
  pipe = pipe.to("cuda")
 
399
  weight_name = (selected.get("weight_name") or "").strip()
400
  if weight_name:
401
  load_kwargs["weight_name"] = weight_name
402
+ if HF_TOKEN:
403
+ load_kwargs["token"] = HF_TOKEN
404
  pipe.load_lora_weights(selected_repo, **load_kwargs)
405
  CURRENT_LOADED_REPO = selected_repo
406