fwwrsd commited on
Commit
4c78bdf
·
verified ·
1 Parent(s): 0bde30d

Upload mirror_all.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. mirror_all.py +141 -0
mirror_all.py ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ import os, sys, tempfile, zipfile, time, traceback
3
+ import requests, re
4
+ from huggingface_hub import HfApi, create_repo, hf_hub_download
5
+
6
+ HF_TOKEN = os.environ["HF_TOKEN"]
7
+ CIVITAI_TOKEN = os.environ["CIVITAI_TOKEN"]
8
+ HF_USER = "fwwrsd"
9
+ WORK = "/workspace/mirror"
10
+ os.makedirs(WORK, exist_ok=True)
11
+ api = HfApi(token=HF_TOKEN)
12
+ UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36"
13
+
14
+ def log(msg):
15
+ print(f"[{time.strftime('%H:%M:%S')}] {msg}", flush=True)
16
+
17
+ def ensure_repo(name):
18
+ full = f"{HF_USER}/{name}"
19
+ try:
20
+ create_repo(repo_id=full, exist_ok=True, token=HF_TOKEN, private=False)
21
+ log(f"repo OK: {full}")
22
+ except Exception as e:
23
+ log(f"repo err (probably exists): {e}")
24
+ return full
25
+
26
+ def civitai_download(version_id, dest_path):
27
+ url = f"https://civitai.com/api/download/models/{version_id}?token={CIVITAI_TOKEN}"
28
+ log(f" CivitAI download v{version_id}")
29
+ with requests.get(url, stream=True, allow_redirects=True, headers={"User-Agent": UA}, timeout=300) as r:
30
+ r.raise_for_status()
31
+ tot = int(r.headers.get("Content-Length", 0))
32
+ log(f" Content-Length: {tot/1e9:.2f} GB")
33
+ downloaded = 0
34
+ last_log = time.time()
35
+ with open(dest_path, "wb") as f:
36
+ for chunk in r.iter_content(chunk_size=8*1024*1024):
37
+ f.write(chunk)
38
+ downloaded += len(chunk)
39
+ if time.time() - last_log > 10:
40
+ log(f" {downloaded/1e9:.2f}/{tot/1e9:.2f} GB ({100*downloaded/max(tot,1):.0f}%)")
41
+ last_log = time.time()
42
+ log(f" DONE: {os.path.getsize(dest_path)/1e9:.2f} GB")
43
+
44
+ def mediafire_download(mf_url, dest_path):
45
+ log(f" MediaFire {mf_url}")
46
+ r = requests.get(mf_url, headers={"User-Agent": UA}, allow_redirects=True, timeout=60)
47
+ m = re.search(r'href="(https?://download\d+\.mediafire\.com/[^"]+)"', r.text)
48
+ if not m: raise RuntimeError("MediaFire: no direct URL")
49
+ direct = m.group(1)
50
+ log(f" direct={direct}")
51
+ with requests.get(direct, headers={"User-Agent": UA}, stream=True, timeout=120) as rr:
52
+ rr.raise_for_status()
53
+ with open(dest_path, "wb") as f:
54
+ for chunk in rr.iter_content(chunk_size=1024*1024): f.write(chunk)
55
+ log(f" DONE: {os.path.getsize(dest_path)/1e6:.1f} MB")
56
+
57
+ def upload_to_hf(local_path, repo_full, name_in_repo):
58
+ log(f" HF upload -> {repo_full}/{name_in_repo}")
59
+ api.upload_file(path_or_fileobj=local_path, path_in_repo=name_in_repo, repo_id=repo_full, token=HF_TOKEN)
60
+ log(f" uploaded")
61
+
62
+ def hf_mirror(src_repo, src_file, dest_repo, dest_file):
63
+ log(f" HF mirror {src_repo}/{src_file} -> {dest_repo}/{dest_file}")
64
+ local = hf_hub_download(repo_id=src_repo, filename=src_file, token=HF_TOKEN, cache_dir="/tmp/hf_cache")
65
+ api.upload_file(path_or_fileobj=local, path_in_repo=dest_file, repo_id=dest_repo, token=HF_TOKEN)
66
+ os.unlink(local) if os.path.exists(local) else None
67
+ log(f" uploaded")
68
+
69
+ def step(num, total, name, fn):
70
+ log(f"")
71
+ log(f"=== [{num}/{total}] {name} ===")
72
+ try:
73
+ fn()
74
+ log(f" STEP {num} OK")
75
+ except Exception as e:
76
+ log(f" STEP {num} FAILED: {e}")
77
+ traceback.print_exc()
78
+
79
+ def s1_lustify():
80
+ repo = ensure_repo("lustify-v7-ggwp")
81
+ p = os.path.join(WORK, "lustify_7.safetensors")
82
+ civitai_download(2155386, p)
83
+ upload_to_hf(p, repo, "lustify_7.safetensors")
84
+ os.unlink(p)
85
+
86
+ def s2_donuts():
87
+ repo = ensure_repo("donuts-delivery-mix-v41")
88
+ p = os.path.join(WORK, "donutsdeliverymixV4_v41.safetensors")
89
+ civitai_download(1739105, p)
90
+ upload_to_hf(p, repo, "donutsdeliverymixV4_v41.safetensors")
91
+ os.unlink(p)
92
+
93
+ def s3_detectors():
94
+ repo = ensure_repo("civitai-misc-detectors")
95
+ for vid, target in [(1309631, "assdetailer.pt"), (582143, "Eyeful_v2-Paired.pt")]:
96
+ z = os.path.join(WORK, f"{vid}.zip")
97
+ civitai_download(vid, z)
98
+ with zipfile.ZipFile(z) as zf:
99
+ pt_files = [m for m in zf.namelist() if m.endswith(".pt")]
100
+ if not pt_files: raise RuntimeError(f"No .pt in {z}: {zf.namelist()}")
101
+ zf.extract(pt_files[0], WORK)
102
+ upload_to_hf(os.path.join(WORK, pt_files[0]), repo, target)
103
+ os.unlink(z)
104
+
105
+ def s4_skin():
106
+ repo = ensure_repo("openmodeldb-skin-upscalers")
107
+ for mf_url, name in [
108
+ ("https://www.mediafire.com/file/py46fnq12hhs5sz/1xSkinContrast-High-SuperUltraCompact.pth", "1xSkinContrast-High-SuperUltraCompact.pth"),
109
+ ("https://www.mediafire.com/file/5qwtnosdfuq9bgl/1xSkinContrast-HighAlternative-SuperUltraCompact.pth", "1xSkinContrast-HighAlternative-SuperUltraCompact.pth"),
110
+ ("https://www.mediafire.com/file/hnvatglitgayunh/1xSkinContrast-SuperUltraCompact.pth", "1xSkinContrast-SuperUltraCompact.pth"),
111
+ ]:
112
+ p = os.path.join(WORK, name)
113
+ try:
114
+ mediafire_download(mf_url, p)
115
+ upload_to_hf(p, repo, name)
116
+ os.unlink(p)
117
+ except Exception as e:
118
+ log(f" skip {name}: {e}")
119
+
120
+ def s5_gemma():
121
+ repo = ensure_repo("gitmylo-ltx2-gemma-mirror")
122
+ for f in [
123
+ "gemma_3_12B_it_fp8_e4m3fn.safetensors",
124
+ "gemma_3_12B_it_nvfp4_uncalibrated.safetensors",
125
+ "ltx-2-19b-dev-fp4_projections_only.safetensors",
126
+ "ltx-2-19b-dev-fp4_video_vae.safetensors",
127
+ "ltx-2-19b-dev-fp4_vocoder.safetensors",
128
+ ]:
129
+ try: hf_mirror("GitMylo/LTX-2-comfy_gemma_fp8_e4m3fn", f, repo, f)
130
+ except Exception as e: log(f" skip {f}: {e}")
131
+
132
+ log("=== mirror_all.py starting ===")
133
+ log(f"HF user: {HF_USER}")
134
+ log(f"Workspace: {WORK}")
135
+ step(1, 5, "LUSTIFY v7", s1_lustify)
136
+ step(2, 5, "Donuts v41", s2_donuts)
137
+ step(3, 5, "NSFW detectors", s3_detectors)
138
+ step(4, 5, "SkinContrast upscalers", s4_skin)
139
+ step(5, 5, "GitMylo gemma mirror", s5_gemma)
140
+ log("")
141
+ log("=== ALL STEPS COMPLETE ===")