CoolKrishh commited on
Commit
142f8e4
Β·
verified Β·
1 Parent(s): 2769eb1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -16
app.py CHANGED
@@ -1,35 +1,31 @@
1
- import torch
2
- from diffusers import StableDiffusionXLPipeline
3
  from huggingface_hub import HfApi, HfFolder, upload_folder
 
 
4
 
5
- # πŸ”Ή Base model your LoRA was trained on
6
  base_model = "stabilityai/stable-diffusion-xl-base-1.0"
7
-
8
- # πŸ”Ή Your LoRA model on Hugging Face
9
  lora_model_id = "CoolKrishh/Comic-SDXL-LoRA"
10
-
11
- # πŸ”Ή Output directory for the merged pipeline
12
  output_dir = "comic-sdxl-full"
13
 
14
  print("⬇️ Loading base model...")
15
  pipe = StableDiffusionXLPipeline.from_pretrained(base_model, torch_dtype=torch.float16)
16
-
17
- print("πŸ”— Attaching LoRA weights...")
18
  pipe.load_lora_weights(lora_model_id)
19
 
20
  print("πŸ’Ύ Saving merged pipeline...")
21
  pipe.save_pretrained(output_dir)
22
 
23
- print("βœ… Saved full pipeline locally!")
 
24
 
25
- # πŸ”Ή Upload merged model to your HF account
26
- api = HfApi()
27
- token = HfFolder.get_token()
28
 
29
- repo_id = "CoolKrishh/Comic-SDXL-Full" # change name if needed
 
30
 
31
  print("☁️ Uploading to Hugging Face Hub...")
32
- api.create_repo(repo_id=repo_id, repo_type="model", private=False, exist_ok=True)
33
  upload_folder(folder_path=output_dir, repo_id=repo_id, repo_type="model", token=token)
34
 
35
- print(f"πŸš€ Uploaded full pipeline to https://huggingface.co/{repo_id}")
 
1
+ import os
 
2
  from huggingface_hub import HfApi, HfFolder, upload_folder
3
+ from diffusers import StableDiffusionXLPipeline
4
+ import torch
5
 
 
6
  base_model = "stabilityai/stable-diffusion-xl-base-1.0"
 
 
7
  lora_model_id = "CoolKrishh/Comic-SDXL-LoRA"
 
 
8
  output_dir = "comic-sdxl-full"
9
 
10
  print("⬇️ Loading base model...")
11
  pipe = StableDiffusionXLPipeline.from_pretrained(base_model, torch_dtype=torch.float16)
12
+ print("πŸ”— Loading LoRA weights...")
 
13
  pipe.load_lora_weights(lora_model_id)
14
 
15
  print("πŸ’Ύ Saving merged pipeline...")
16
  pipe.save_pretrained(output_dir)
17
 
18
+ # βœ… Use token from environment
19
+ token = os.getenv("HF_TOKEN")
20
 
21
+ if not token:
22
+ raise ValueError("❌ No HF_TOKEN found. Add it in your Space secrets.")
 
23
 
24
+ api = HfApi()
25
+ repo_id = "CoolKrishh/Comic-SDXL-Full"
26
 
27
  print("☁️ Uploading to Hugging Face Hub...")
28
+ api.create_repo(repo_id=repo_id, repo_type="model", private=False, exist_ok=True, token=token)
29
  upload_folder(folder_path=output_dir, repo_id=repo_id, repo_type="model", token=token)
30
 
31
+ print(f"πŸš€ Uploaded successfully to https://huggingface.co/{repo_id}")