K00B404 commited on
Commit
bdf7657
·
verified ·
1 Parent(s): 9ff236d

Create lora_saver.py

Browse files
Files changed (1) hide show
  1. lora_saver.py +41 -0
lora_saver.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import shutil
3
+ from huggingface_hub import hf_hub_download, upload_folder, HfApi
4
+ from loras import loras
5
+
6
+ # Your Hugging Face model repo
7
+ HF_REPO = "K00B404/LoraStack"
8
+
9
+
10
+ def download_lora(repo_id, save_dir="loras"):
11
+ """Download all files from a LoRA repository."""
12
+ model_name = repo_id.split("/")[-1]
13
+ target_dir = os.path.join(save_dir, model_name)
14
+ os.makedirs(target_dir, exist_ok=True)
15
+
16
+ # Get file list from repo
17
+ api = HfApi()
18
+ files = api.list_repo_files(repo_id, repo_type="model")
19
+
20
+ for file in files:
21
+ print(f"Downloading {file} from {repo_id}...")
22
+ hf_hub_download(repo_id=repo_id, filename=file, local_dir=target_dir)
23
+
24
+ return target_dir
25
+
26
+ def upload_to_hf(local_dir, hf_repo):
27
+ """Upload the downloaded LoRA folder to Hugging Face."""
28
+ print(f"Uploading {local_dir} to {hf_repo}...")
29
+ upload_folder(folder_path=local_dir, repo_id=hf_repo, repo_type="model")
30
+
31
+ def main():
32
+ """Fetch, download, and upload LoRAs to Hugging Face."""
33
+ for repo_id in loras:
34
+ local_dir = download_lora(repo_id)
35
+ upload_to_hf(local_dir, HF_REPO)
36
+ print(f"Successfully uploaded {repo_id} to {HF_REPO}\n")
37
+
38
+ print("All LoRAs processed!")
39
+
40
+ if __name__ == "__main__":
41
+ main()