goumsss Claude Sonnet 4.6 commited on
Commit
a057332
·
1 Parent(s): 9171f58

Pass HF_TOKEN to FluxPipeline for gated model access on HF Spaces

Browse files

Reads HF_TOKEN (or HUGGING_FACE_HUB_TOKEN) env var and passes it to
from_pretrained(). Without this the Space gets a 401 on the gated
FLUX.1-schnell repo. Also logs whether the token is set.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Files changed (1) hide show
  1. image_generator.py +3 -1
image_generator.py CHANGED
@@ -98,10 +98,12 @@ def get_pipeline():
98
 
99
  from diffusers import FluxPipeline
100
 
101
- print("Loading FLUX.1-schnell pipeline…")
 
102
  _pipe = FluxPipeline.from_pretrained(
103
  "black-forest-labs/FLUX.1-schnell",
104
  torch_dtype=torch.bfloat16,
 
105
  )
106
 
107
  if torch.cuda.is_available():
 
98
 
99
  from diffusers import FluxPipeline
100
 
101
+ hf_token = os.environ.get("HF_TOKEN") or os.environ.get("HUGGING_FACE_HUB_TOKEN")
102
+ print(f"Loading FLUX.1-schnell pipeline… (token={'set' if hf_token else 'NOT SET'})")
103
  _pipe = FluxPipeline.from_pretrained(
104
  "black-forest-labs/FLUX.1-schnell",
105
  torch_dtype=torch.bfloat16,
106
+ token=hf_token,
107
  )
108
 
109
  if torch.cuda.is_available():