Spaces:
Runtime error
Runtime error
File size: 2,088 Bytes
ee19e85 142f8e4 918a8ad 2769eb1 12c784f f5d14b3 12c784f e9522e9 12c784f ee19e85 12c784f 2769eb1 12c784f 7338dd2 9499889 12c784f 2769eb1 ee19e85 7338dd2 f5d14b3 ee19e85 f5d14b3 12c784f e84004d 2769eb1 ee19e85 7338dd2 ee19e85 12c784f ee19e85 12c784f ee19e85 918a8ad ee19e85 7338dd2 ee19e85 7338dd2 ee19e85 12c784f ee19e85 12c784f ee19e85 12c784f e84004d ee19e85 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
import os, torch, shutil
from diffusers import StableDiffusionXLPipeline
from huggingface_hub import HfApi, hf_hub_download, create_repo
# ====================== CONFIG ======================
BASE_MODEL = "stabilityai/stable-diffusion-xl-base-1.0"
LORA_REPO = "CoolKrishh/Comic-SDXL-LoRA"
LORA_FILE = "Comic-SDXL.safetensors"
DEST_REPO = "CoolKrishh/mythic-sdxl"
OUTPUT_CKPT = "mythic-sdxl.safetensors"
OUTPUT_DIR = "/app/out"
# ===================================================
TOKEN = os.getenv("HF_TOKEN")
if not TOKEN:
raise ValueError("β HF_TOKEN not set!")
api = HfApi(token=TOKEN)
create_repo(repo_id=DEST_REPO, exist_ok=True, token=TOKEN)
print("β¬ Downloading LoRA...")
lora_path = hf_hub_download(LORA_REPO, LORA_FILE, token=TOKEN)
print("π Loading SDXL base...")
pipe = StableDiffusionXLPipeline.from_pretrained(
BASE_MODEL, torch_dtype=torch.float16
)
print("𧬠Merging LoRA...")
pipe.load_lora_weights(lora_path, adapter_name="default")
pipe.fuse_lora()
# Ensure output folder exists
os.makedirs(OUTPUT_DIR, exist_ok=True)
print("πΎ Saving merged pipeline...")
pipe.save_pretrained(OUTPUT_DIR, safe_serialization=True)
# ---- FIND REAL SAVED SAFETENSORS ----
print("π Scanning saved files...")
found = None
for f in os.listdir(OUTPUT_DIR):
if f.endswith(".safetensors"):
found = f
break
if not found:
raise FileNotFoundError("β No .safetensors file was created by diffusers!")
src = os.path.join(OUTPUT_DIR, found)
dst = os.path.join(OUTPUT_DIR, OUTPUT_CKPT)
print(f"π Renaming:\n {src}\n β {dst}")
shutil.move(src, dst)
# ---- VERIFY FINAL FILE EXISTS ----
if not os.path.exists(dst):
raise FileNotFoundError(f"β Still missing after rename: {dst}")
print(f"β
Final model file ready at:\n{dst}")
# ---- UPLOAD ----
print("β Uploading to Hugging Face...")
api.upload_file(
path_or_fileobj=dst,
path_in_repo=OUTPUT_CKPT,
repo_id=DEST_REPO,
token=TOKEN
)
print("\nπ SUCCESS! Your model is now uploaded & inference-ready.")
print(f"π https://huggingface.co/{DEST_REPO}")
|