CoolKrishh commited on
Commit
918a8ad
Β·
verified Β·
1 Parent(s): 12c784f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -18
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 diffusers.pipelines.stable_diffusion.convert_from_diffusers import convert_sdxl_checkpoint
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 temporary merged diffusers pipeline
45
- TMP_DIR = "merged_pipeline"
46
- print("πŸ’Ύ Saving temporary merged pipeline...")
47
- pipe.save_pretrained(TMP_DIR, safe_serialization=True)
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
- print(f"βœ… Checkpoint created: {OUTPUT_CKPT}")
 
 
 
 
 
 
58
 
59
  # Upload to Hugging Face
60
- print("☁️ Uploading model checkpoint to HF...")
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"βœ… Your model will now support Inference API:")
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}")