Spaces:
Running
on
Zero
Running
on
Zero
Fix: Login before import, use use_auth_token param, add debug logging
Browse files
app.py
CHANGED
|
@@ -4,22 +4,28 @@ import os
|
|
| 4 |
import random
|
| 5 |
import spaces
|
| 6 |
import torch
|
| 7 |
-
from diffusers import Flux2KleinPipeline
|
| 8 |
from huggingface_hub import login
|
| 9 |
|
| 10 |
# Authenticate with HF token for gated model access
|
| 11 |
-
|
| 12 |
-
if
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
dtype = torch.bfloat16
|
| 16 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 17 |
|
|
|
|
| 18 |
pipe = Flux2KleinPipeline.from_pretrained(
|
| 19 |
"black-forest-labs/FLUX.2-klein-9B",
|
| 20 |
torch_dtype=dtype,
|
| 21 |
-
|
| 22 |
-
)
|
| 23 |
|
| 24 |
MAX_SEED = np.iinfo(np.int32).max
|
| 25 |
MAX_IMAGE_SIZE = 2048
|
|
|
|
| 4 |
import random
|
| 5 |
import spaces
|
| 6 |
import torch
|
|
|
|
| 7 |
from huggingface_hub import login
|
| 8 |
|
| 9 |
# Authenticate with HF token for gated model access
|
| 10 |
+
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 11 |
+
if HF_TOKEN:
|
| 12 |
+
print(f"HF_TOKEN found, logging in...")
|
| 13 |
+
login(token=HF_TOKEN)
|
| 14 |
+
print("Login successful")
|
| 15 |
+
else:
|
| 16 |
+
print("WARNING: No HF_TOKEN found in environment!")
|
| 17 |
+
|
| 18 |
+
from diffusers import Flux2KleinPipeline
|
| 19 |
|
| 20 |
dtype = torch.bfloat16
|
| 21 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 22 |
|
| 23 |
+
print(f"Loading model with token: {'Yes' if HF_TOKEN else 'No'}")
|
| 24 |
pipe = Flux2KleinPipeline.from_pretrained(
|
| 25 |
"black-forest-labs/FLUX.2-klein-9B",
|
| 26 |
torch_dtype=dtype,
|
| 27 |
+
use_auth_token=HF_TOKEN
|
| 28 |
+
)
|
| 29 |
|
| 30 |
MAX_SEED = np.iinfo(np.int32).max
|
| 31 |
MAX_IMAGE_SIZE = 2048
|