Switch text encoder to HF Hub download instead of bucket mount
Browse filesUses hf_hub_download from ponpoke/flux2-klein-9b-uncensored-text-encoder
for faster download via CDN + automatic HF caching.
Co-Authored-By: Oz <oz-agent@warp.dev>
app.py
CHANGED
|
@@ -19,7 +19,8 @@ from config import (
|
|
| 19 |
MAX_SEED,
|
| 20 |
MAX_LORA_SLOTS,
|
| 21 |
PERSISTENT_LORA_CATALOG_PATH,
|
| 22 |
-
|
|
|
|
| 23 |
)
|
| 24 |
from ui_theme import orange_red_theme
|
| 25 |
from upscale import UPSCALE_MODELS, apply_realesrgan
|
|
@@ -326,15 +327,18 @@ pipe = _PipeClass.from_pretrained(MODEL_REPO, torch_dtype=torch.bfloat16).to(dev
|
|
| 326 |
print(f"Model loaded successfully: FLUX.2 Klein {MODEL_VARIANT}")
|
| 327 |
|
| 328 |
# ββ Replace text encoder with abliterated (uncensored) version βββββββββββ
|
| 329 |
-
|
|
|
|
| 330 |
from safetensors.torch import load_file
|
| 331 |
-
print(f"
|
| 332 |
-
|
|
|
|
|
|
|
| 333 |
pipe.text_encoder.load_state_dict(state_dict, strict=True)
|
| 334 |
pipe.text_encoder.to(device=device, dtype=torch.bfloat16)
|
| 335 |
print("Abliterated text encoder loaded β safety filters removed.")
|
| 336 |
-
|
| 337 |
-
print(f"Abliterated text encoder
|
| 338 |
|
| 339 |
|
| 340 |
# ββ UI helper callbacks ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
| 19 |
MAX_SEED,
|
| 20 |
MAX_LORA_SLOTS,
|
| 21 |
PERSISTENT_LORA_CATALOG_PATH,
|
| 22 |
+
UNCENSORED_TE_REPO,
|
| 23 |
+
UNCENSORED_TE_FILE,
|
| 24 |
)
|
| 25 |
from ui_theme import orange_red_theme
|
| 26 |
from upscale import UPSCALE_MODELS, apply_realesrgan
|
|
|
|
| 327 |
print(f"Model loaded successfully: FLUX.2 Klein {MODEL_VARIANT}")
|
| 328 |
|
| 329 |
# ββ Replace text encoder with abliterated (uncensored) version βββββββββββ
|
| 330 |
+
try:
|
| 331 |
+
from huggingface_hub import hf_hub_download
|
| 332 |
from safetensors.torch import load_file
|
| 333 |
+
print(f"Downloading abliterated text encoder from {UNCENSORED_TE_REPO}...")
|
| 334 |
+
te_path = hf_hub_download(repo_id=UNCENSORED_TE_REPO, filename=UNCENSORED_TE_FILE)
|
| 335 |
+
print(f"Loading abliterated weights from {te_path}...")
|
| 336 |
+
state_dict = load_file(te_path)
|
| 337 |
pipe.text_encoder.load_state_dict(state_dict, strict=True)
|
| 338 |
pipe.text_encoder.to(device=device, dtype=torch.bfloat16)
|
| 339 |
print("Abliterated text encoder loaded β safety filters removed.")
|
| 340 |
+
except Exception as e:
|
| 341 |
+
print(f"Abliterated text encoder unavailable ({e}) β using stock encoder.")
|
| 342 |
|
| 343 |
|
| 344 |
# ββ UI helper callbacks ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
config.py
CHANGED
|
@@ -31,8 +31,6 @@ PERSISTENT_LORA_CATALOG_PATH = os.environ.get(
|
|
| 31 |
)
|
| 32 |
|
| 33 |
# Abliterated (uncensored) text encoder β replaces the stock Qwen3 text encoder
|
| 34 |
-
# weights after pipeline load.
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
"/loras-flux/fk9b-uncensored-text-encoder/model.safetensors",
|
| 38 |
-
)
|
|
|
|
| 31 |
)
|
| 32 |
|
| 33 |
# Abliterated (uncensored) text encoder β replaces the stock Qwen3 text encoder
|
| 34 |
+
# weights after pipeline load. Downloaded via HF Hub for speed + caching.
|
| 35 |
+
UNCENSORED_TE_REPO = "ponpoke/flux2-klein-9b-uncensored-text-encoder"
|
| 36 |
+
UNCENSORED_TE_FILE = "model.safetensors"
|
|
|
|
|
|