Add abliterated (uncensored) text encoder support
Browse files- config.py: add UNCENSORED_TE_PATH pointing to bucket-mounted model
- app.py: load abliterated Qwen3 weights into pipe.text_encoder after
pipeline init, with graceful fallback to stock encoder
- Remove stale loras/ directory (superseded by bucket catalog)
Co-Authored-By: Oz <oz-agent@warp.dev>
README.md
CHANGED
|
@@ -8,5 +8,5 @@ sdk_version: 6.15.2
|
|
| 8 |
app_file: app.py
|
| 9 |
pinned: true
|
| 10 |
license: apache-2.0
|
| 11 |
-
short_description: try flux.2 klein9b loras
|
| 12 |
---
|
|
|
|
| 8 |
app_file: app.py
|
| 9 |
pinned: true
|
| 10 |
license: apache-2.0
|
| 11 |
+
short_description: try flux.2 klein9b loras + abliterated text encoder
|
| 12 |
---
|
app.py
CHANGED
|
@@ -19,6 +19,7 @@ from config import (
|
|
| 19 |
MAX_SEED,
|
| 20 |
MAX_LORA_SLOTS,
|
| 21 |
PERSISTENT_LORA_CATALOG_PATH,
|
|
|
|
| 22 |
)
|
| 23 |
from ui_theme import orange_red_theme
|
| 24 |
from upscale import UPSCALE_MODELS, apply_realesrgan
|
|
@@ -324,6 +325,17 @@ print(f"Loading FLUX.2 Klein {MODEL_VARIANT} from {MODEL_REPO}...")
|
|
| 324 |
pipe = _PipeClass.from_pretrained(MODEL_REPO, torch_dtype=torch.bfloat16).to(device)
|
| 325 |
print(f"Model loaded successfully: FLUX.2 Klein {MODEL_VARIANT}")
|
| 326 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 327 |
|
| 328 |
# ββ UI helper callbacks ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 329 |
|
|
|
|
| 19 |
MAX_SEED,
|
| 20 |
MAX_LORA_SLOTS,
|
| 21 |
PERSISTENT_LORA_CATALOG_PATH,
|
| 22 |
+
UNCENSORED_TE_PATH,
|
| 23 |
)
|
| 24 |
from ui_theme import orange_red_theme
|
| 25 |
from upscale import UPSCALE_MODELS, apply_realesrgan
|
|
|
|
| 325 |
pipe = _PipeClass.from_pretrained(MODEL_REPO, torch_dtype=torch.bfloat16).to(device)
|
| 326 |
print(f"Model loaded successfully: FLUX.2 Klein {MODEL_VARIANT}")
|
| 327 |
|
| 328 |
+
# ββ Replace text encoder with abliterated (uncensored) version βββββββββββ
|
| 329 |
+
if os.path.isfile(UNCENSORED_TE_PATH):
|
| 330 |
+
from safetensors.torch import load_file
|
| 331 |
+
print(f"Loading abliterated text encoder from {UNCENSORED_TE_PATH}...")
|
| 332 |
+
state_dict = load_file(UNCENSORED_TE_PATH)
|
| 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 |
+
else:
|
| 337 |
+
print(f"Abliterated text encoder not found at {UNCENSORED_TE_PATH} β using stock encoder.")
|
| 338 |
+
|
| 339 |
|
| 340 |
# ββ UI helper callbacks ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 341 |
|
config.py
CHANGED
|
@@ -29,3 +29,10 @@ PERSISTENT_LORA_CATALOG_PATH = os.environ.get(
|
|
| 29 |
"PERSISTENT_LORA_CATALOG_PATH",
|
| 30 |
"/loras-flux/config/lorasplayground.json",
|
| 31 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
"PERSISTENT_LORA_CATALOG_PATH",
|
| 30 |
"/loras-flux/config/lorasplayground.json",
|
| 31 |
)
|
| 32 |
+
|
| 33 |
+
# Abliterated (uncensored) text encoder β replaces the stock Qwen3 text encoder
|
| 34 |
+
# weights after pipeline load. Set UNCENSORED_TE_PATH env var to override.
|
| 35 |
+
UNCENSORED_TE_PATH = os.environ.get(
|
| 36 |
+
"UNCENSORED_TE_PATH",
|
| 37 |
+
"/loras-flux/fk9b-uncensored-text-encoder/model.safetensors",
|
| 38 |
+
)
|