Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
import os, torch
|
| 2 |
-
from huggingface_hub import HfApi, hf_hub_download, create_repo
|
| 3 |
from diffusers import StableDiffusionXLPipeline
|
| 4 |
-
from
|
| 5 |
|
| 6 |
# ====================== CONFIG ======================
|
| 7 |
BASE_MODEL = "stabilityai/stable-diffusion-xl-base-1.0"
|
|
@@ -41,23 +40,23 @@ print("𧬠Merging LoRA into model...")
|
|
| 41 |
pipe.load_lora_weights(lora_path)
|
| 42 |
pipe.fuse_lora()
|
| 43 |
|
| 44 |
-
# Save
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
# Convert to single safetensors checkpoint
|
| 50 |
-
print("π Converting merged model to .safetensors checkpoint...")
|
| 51 |
-
convert_sdxl_checkpoint(
|
| 52 |
-
TMP_DIR,
|
| 53 |
-
OUTPUT_CKPT,
|
| 54 |
-
use_safetensors=True
|
| 55 |
)
|
| 56 |
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
# Upload to Hugging Face
|
| 60 |
-
print("βοΈ Uploading
|
| 61 |
api.upload_file(
|
| 62 |
path_or_fileobj=OUTPUT_CKPT,
|
| 63 |
path_in_repo=OUTPUT_CKPT,
|
|
@@ -65,6 +64,5 @@ api.upload_file(
|
|
| 65 |
token=TOKEN
|
| 66 |
)
|
| 67 |
|
| 68 |
-
print("\nπ DONE!")
|
| 69 |
-
print(f"β
|
| 70 |
-
print(f"https://huggingface.co/{DEST_REPO}")
|
|
|
|
| 1 |
import os, torch
|
|
|
|
| 2 |
from diffusers import StableDiffusionXLPipeline
|
| 3 |
+
from huggingface_hub import HfApi, hf_hub_download, create_repo
|
| 4 |
|
| 5 |
# ====================== CONFIG ======================
|
| 6 |
BASE_MODEL = "stabilityai/stable-diffusion-xl-base-1.0"
|
|
|
|
| 40 |
pipe.load_lora_weights(lora_path)
|
| 41 |
pipe.fuse_lora()
|
| 42 |
|
| 43 |
+
# Save merged checkpoint
|
| 44 |
+
print("πΎ Saving merged model to safetensors...")
|
| 45 |
+
pipe.save_pretrained(
|
| 46 |
+
"./out",
|
| 47 |
+
safe_serialization=True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
)
|
| 49 |
|
| 50 |
+
# Rename the main model file to deployment format
|
| 51 |
+
for file in os.listdir("./out"):
|
| 52 |
+
if file.endswith(".safetensors"):
|
| 53 |
+
os.rename(f"./out/{file}", OUTPUT_CKPT)
|
| 54 |
+
break
|
| 55 |
+
|
| 56 |
+
print(f"β
Model saved as {OUTPUT_CKPT}")
|
| 57 |
|
| 58 |
# Upload to Hugging Face
|
| 59 |
+
print("βοΈ Uploading to Hugging Face...")
|
| 60 |
api.upload_file(
|
| 61 |
path_or_fileobj=OUTPUT_CKPT,
|
| 62 |
path_in_repo=OUTPUT_CKPT,
|
|
|
|
| 64 |
token=TOKEN
|
| 65 |
)
|
| 66 |
|
| 67 |
+
print("\nπ DONE! Model is now inference-ready")
|
| 68 |
+
print(f"β
https://huggingface.co/{DEST_REPO}")
|
|
|