Spaces:
Build error
Build error
Commit
·
fbd80d3
0
Parent(s):
Duplicate from umair007/all_in_one_converter_test
Browse files- .gitattributes +34 -0
- README.md +12 -0
- app.py +595 -0
- packages.txt +1 -0
- requirements.txt +13 -0
.gitattributes
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Converter
|
3 |
+
emoji: ♻
|
4 |
+
colorFrom: green
|
5 |
+
colorTo: green
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.10.1
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: mit
|
11 |
+
duplicated_from: umair007/all_in_one_converter_test
|
12 |
+
---
|
app.py
ADDED
@@ -0,0 +1,595 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os, gdown
|
2 |
+
import aria2p
|
3 |
+
import subprocess
|
4 |
+
import requests
|
5 |
+
import numpy as np
|
6 |
+
import gradio as gr
|
7 |
+
from diffusers import FlaxStableDiffusionPipeline
|
8 |
+
import torch
|
9 |
+
from safetensors.torch import save_file, load_file
|
10 |
+
from huggingface_hub import model_info, create_repo, create_branch, upload_folder
|
11 |
+
from huggingface_hub.utils import RepositoryNotFoundError, RevisionNotFoundError
|
12 |
+
|
13 |
+
def check_link(torrent_url):
|
14 |
+
if torrent_url.endswith('.torrent') or torrent_url.startswith('magnet:?xt=urn:btih:'):
|
15 |
+
return True
|
16 |
+
else:
|
17 |
+
return False
|
18 |
+
|
19 |
+
def download_torrent(torrent_url):
|
20 |
+
# Create the file directory if it doesn't exist
|
21 |
+
os.makedirs("torrent", exist_ok=True)
|
22 |
+
if check_link(torrent_url):
|
23 |
+
# command to download torrent file
|
24 |
+
command = os.system(f"aria2c --dir=torrent --summary-interval=10 --seed-ratio=0.1 --allow-overwrite=true {torrent_url}")
|
25 |
+
return "download torrent done!"
|
26 |
+
else:
|
27 |
+
# command to download regular file
|
28 |
+
command = os.system(f"aria2c --dir=torrent --summary-interval=10 -c -x 10 -k 1M -s 10 {torrent_url}")
|
29 |
+
return "download torrent done!"
|
30 |
+
subprocess.run(command, shell=True)
|
31 |
+
|
32 |
+
def push_torrent(model_to, token, branch):
|
33 |
+
try:
|
34 |
+
repo_exists = True
|
35 |
+
r_info = model_info(model_to, token=token)
|
36 |
+
except RepositoryNotFoundError:
|
37 |
+
repo_exists = False
|
38 |
+
finally:
|
39 |
+
if repo_exists:
|
40 |
+
print(r_info)
|
41 |
+
else:
|
42 |
+
create_repo(model_to, private=True, token=token)
|
43 |
+
try:
|
44 |
+
branch_exists = True
|
45 |
+
b_info = model_info(model_to, revision=branch, token=token)
|
46 |
+
except RevisionNotFoundError:
|
47 |
+
branch_exists = False
|
48 |
+
finally:
|
49 |
+
if branch_exists:
|
50 |
+
print(b_info)
|
51 |
+
else:
|
52 |
+
create_branch(model_to, branch=branch, token=token)
|
53 |
+
# Create the torrent directory if it doesn't exist
|
54 |
+
os.makedirs("torrent", exist_ok=True)
|
55 |
+
upload_folder(folder_path="torrent", path_in_repo="", revision=branch, repo_id=model_to, commit_message=f"torrent", token=token)
|
56 |
+
return "push torrent done!"
|
57 |
+
|
58 |
+
def delete_torrent():
|
59 |
+
os.system(f"rm -rf torrent")
|
60 |
+
return "delete torrent done!"
|
61 |
+
|
62 |
+
def download_file(file_url_1, file_name_1):
|
63 |
+
# Create the file directory if it doesn't exist
|
64 |
+
os.makedirs("file", exist_ok=True)
|
65 |
+
|
66 |
+
if "drive.google.com" in file_url_1:
|
67 |
+
gdown.download(url=file_url_1, output=f"file/{file_name_1}", quiet=False, fuzzy=True)
|
68 |
+
return "download file done!"
|
69 |
+
elif "civitai.com" in file_url_1:
|
70 |
+
os.system(f"aria2c --dir=file/{file_name_1} --summary-interval=10 -c -x 10 -k 1M -s 10 {file_url_1}")
|
71 |
+
return "download file done!"
|
72 |
+
elif "huggingface.co" in file_url_1:
|
73 |
+
os.system(f"aria2c --dir=file/{file_name_1} --summary-interval=10 -c -x 10 -k 1M -s 10 {file_url_1}")
|
74 |
+
return "download file done!"
|
75 |
+
else:
|
76 |
+
try:
|
77 |
+
response = requests.get(ckpt_url_1)
|
78 |
+
if response.status_code == 200:
|
79 |
+
with open(f"file/{file_name_1}", "wb") as f:
|
80 |
+
return "download file done!"
|
81 |
+
else:
|
82 |
+
return "error download file!"
|
83 |
+
except Exception as e:
|
84 |
+
return "error download file!"
|
85 |
+
|
86 |
+
|
87 |
+
|
88 |
+
def push_file_1(model_to, token, branch):
|
89 |
+
try:
|
90 |
+
repo_exists = True
|
91 |
+
r_info = model_info(model_to, token=token)
|
92 |
+
except RepositoryNotFoundError:
|
93 |
+
repo_exists = False
|
94 |
+
finally:
|
95 |
+
if repo_exists:
|
96 |
+
print(r_info)
|
97 |
+
else:
|
98 |
+
create_repo(model_to, private=True, token=token)
|
99 |
+
try:
|
100 |
+
branch_exists = True
|
101 |
+
b_info = model_info(model_to, revision=branch, token=token)
|
102 |
+
except RevisionNotFoundError:
|
103 |
+
branch_exists = False
|
104 |
+
finally:
|
105 |
+
if branch_exists:
|
106 |
+
print(b_info)
|
107 |
+
else:
|
108 |
+
create_branch(model_to, branch=branch, token=token)
|
109 |
+
# Create the ckpt directory if it doesn't exist
|
110 |
+
os.makedirs("file", exist_ok=True)
|
111 |
+
upload_folder(folder_path="file", path_in_repo="", revision=branch, repo_id=model_to, commit_message=f"file", token=token)
|
112 |
+
return "push files done!"
|
113 |
+
|
114 |
+
def delete_file():
|
115 |
+
os.system(f"rm -rf file")
|
116 |
+
return "delete ckpt done!"
|
117 |
+
|
118 |
+
def download_ckpt(ckpt_url, ckpt_name):
|
119 |
+
# Create the ckpt directory if it doesn't exist
|
120 |
+
os.makedirs("ckpt", exist_ok=True)
|
121 |
+
|
122 |
+
if "drive.google.com" in ckpt_url:
|
123 |
+
gdown.download(url=ckpt_url, output=f"ckpt/{ckpt_name}.ckpt", quiet=False, fuzzy=True)
|
124 |
+
return "download ckpt done!"
|
125 |
+
elif "civitai.com" in ckpt_url:
|
126 |
+
os.system(f"aria2c --dir=ckpt/{ckpt_name} --summary-interval=10 -c -x 10 -k 1M -s 10 {ckpt_url}")
|
127 |
+
return "download ckpt done!"
|
128 |
+
elif "huggingface.co" in ckpt_url:
|
129 |
+
os.system(f"aria2c --dir=ckpt/{ckpt_name} --summary-interval=10 -c -x 10 -k 1M -s 10 {ckpt_url}")
|
130 |
+
return "download ckpt done!"
|
131 |
+
else:
|
132 |
+
try:
|
133 |
+
response = requests.get(ckpt_url)
|
134 |
+
if response.status_code == 200:
|
135 |
+
with open(f"ckpt/{ckpt_name}.ckpt", "wb") as f:
|
136 |
+
return "download ckpt done!"
|
137 |
+
else:
|
138 |
+
return "error download ckpt!"
|
139 |
+
except Exception as e:
|
140 |
+
return "error download ckpt!"
|
141 |
+
|
142 |
+
|
143 |
+
def to_pt():
|
144 |
+
os.system("wget -q https://raw.githubusercontent.com/huggingface/diffusers/main/scripts/convert_original_stable_diffusion_to_diffusers.py")
|
145 |
+
os.system(f"python3 convert_original_stable_diffusion_to_diffusers.py --checkpoint_path model.ckpt --dump_path pt")
|
146 |
+
return "convert to pt done!"
|
147 |
+
|
148 |
+
def push_pt(model_to, token, branch):
|
149 |
+
try:
|
150 |
+
repo_exists = True
|
151 |
+
r_info = model_info(model_to, token=token)
|
152 |
+
except RepositoryNotFoundError:
|
153 |
+
repo_exists = False
|
154 |
+
finally:
|
155 |
+
if repo_exists:
|
156 |
+
print(r_info)
|
157 |
+
else:
|
158 |
+
create_repo(model_to, private=True, token=token)
|
159 |
+
try:
|
160 |
+
branch_exists = True
|
161 |
+
b_info = model_info(model_to, revision=branch, token=token)
|
162 |
+
except RevisionNotFoundError:
|
163 |
+
branch_exists = False
|
164 |
+
finally:
|
165 |
+
if branch_exists:
|
166 |
+
print(b_info)
|
167 |
+
else:
|
168 |
+
create_branch(model_to, branch=branch, token=token)
|
169 |
+
upload_folder(folder_path="pt", path_in_repo="", revision=branch, repo_id=model_to, commit_message=f"pt", token=token)
|
170 |
+
return "push pt done!"
|
171 |
+
|
172 |
+
def delete_pt():
|
173 |
+
os.system(f"rm -rf pt")
|
174 |
+
return "delete pt done!"
|
175 |
+
|
176 |
+
def clone_pt(model_url):
|
177 |
+
os.system("git lfs install")
|
178 |
+
os.system(f"git clone https://huggingface.co/{model_url} pt")
|
179 |
+
return "clone pt done!"
|
180 |
+
|
181 |
+
def to_flax():
|
182 |
+
pipe, params = FlaxStableDiffusionPipeline.from_pretrained("pt", from_pt=True)
|
183 |
+
pipe.save_pretrained("flax", params=params)
|
184 |
+
return "convert to flax done!"
|
185 |
+
|
186 |
+
def push_flax(model_to, token, branch):
|
187 |
+
try:
|
188 |
+
repo_exists = True
|
189 |
+
r_info = model_info(model_to, token=token)
|
190 |
+
except RepositoryNotFoundError:
|
191 |
+
repo_exists = False
|
192 |
+
finally:
|
193 |
+
if repo_exists:
|
194 |
+
print(r_info)
|
195 |
+
else:
|
196 |
+
create_repo(model_to, private=True, token=token)
|
197 |
+
try:
|
198 |
+
branch_exists = True
|
199 |
+
b_info = model_info(model_to, revision=branch, token=token)
|
200 |
+
except RevisionNotFoundError:
|
201 |
+
branch_exists = False
|
202 |
+
finally:
|
203 |
+
if branch_exists:
|
204 |
+
print(b_info)
|
205 |
+
else:
|
206 |
+
create_branch(model_to, branch=branch, token=token)
|
207 |
+
upload_folder(folder_path="flax", path_in_repo="", revision=branch, repo_id=model_to, commit_message=f"flax", token=token)
|
208 |
+
return "push flax done!"
|
209 |
+
|
210 |
+
def delete_flax():
|
211 |
+
os.system(f"rm -rf flax")
|
212 |
+
return "delete flax done!"
|
213 |
+
|
214 |
+
def to_ckpt(ckpt_name):
|
215 |
+
os.system("wget -q https://raw.githubusercontent.com/huggingface/diffusers/main/scripts/convert_diffusers_to_original_stable_diffusion.py")
|
216 |
+
os.system("mkdir ckpt")
|
217 |
+
os.system(f"python3 convert_diffusers_to_original_stable_diffusion.py --model_path pt --checkpoint_path ckpt/{ckpt_name}.ckpt")
|
218 |
+
return "convert to ckpt done!"
|
219 |
+
|
220 |
+
def push_ckpt(model_to, token, branch):
|
221 |
+
try:
|
222 |
+
repo_exists = True
|
223 |
+
r_info = model_info(model_to, token=token)
|
224 |
+
except RepositoryNotFoundError:
|
225 |
+
repo_exists = False
|
226 |
+
finally:
|
227 |
+
if repo_exists:
|
228 |
+
print(r_info)
|
229 |
+
else:
|
230 |
+
create_repo(model_to, private=True, token=token)
|
231 |
+
try:
|
232 |
+
branch_exists = True
|
233 |
+
b_info = model_info(model_to, revision=branch, token=token)
|
234 |
+
except RevisionNotFoundError:
|
235 |
+
branch_exists = False
|
236 |
+
finally:
|
237 |
+
if branch_exists:
|
238 |
+
print(b_info)
|
239 |
+
else:
|
240 |
+
create_branch(model_to, branch=branch, token=token)
|
241 |
+
upload_folder(folder_path="ckpt", path_in_repo="", revision=branch, repo_id=model_to, commit_message=f"ckpt", token=token)
|
242 |
+
return "push ckpt done!"
|
243 |
+
|
244 |
+
def delete_ckpt():
|
245 |
+
os.system(f"rm -rf ckpt")
|
246 |
+
return "delete ckpt done!"
|
247 |
+
|
248 |
+
def download_ckpt(ckpt_url_2, ckpt_name_2):
|
249 |
+
# Create the ckpt directory if it doesn't exist
|
250 |
+
os.makedirs("ckpt", exist_ok=True)
|
251 |
+
|
252 |
+
if "drive.google.com" in ckpt_url_2:
|
253 |
+
gdown.download(url=ckpt_url_2, output=f"ckpt/{ckpt_name_2}.ckpt", quiet=False, fuzzy=True)
|
254 |
+
return "download ckpt done!"
|
255 |
+
elif "civitai.com" in ckpt_url_2:
|
256 |
+
os.system(f"aria2c --dir=ckpt/{ckpt_name_2}.ckpt --summary-interval=10 -c -x 10 -k 1M -s 10 {ckpt_url_2}")
|
257 |
+
return "download ckpt done!"
|
258 |
+
elif "huggingface.co" in ckpt_url_2:
|
259 |
+
os.system(f"aria2c --dir=ckpt/{ckpt_name_2}.ckpt --summary-interval=10 -c -x 10 -k 1M -s 10 {ckpt_url_2}")
|
260 |
+
return "download ckpt done!"
|
261 |
+
else:
|
262 |
+
try:
|
263 |
+
response = requests.get(ckpt_url_2)
|
264 |
+
if response.status_code == 200:
|
265 |
+
with open(f"ckpt/{ckpt_name_2}.ckpt", "wb") as f:
|
266 |
+
return "download ckpt done!"
|
267 |
+
else:
|
268 |
+
return "error download ckpt!"
|
269 |
+
except Exception as e:
|
270 |
+
return "error download ckpt!"
|
271 |
+
|
272 |
+
|
273 |
+
def to_safetensors(ckpt_name_2, safetensors_name_2):
|
274 |
+
os.system("mkdir safetensors")
|
275 |
+
weights = torch.load(f"ckpt/{ckpt_name_2}.ckpt")
|
276 |
+
if "state_dict" in weights:
|
277 |
+
weights = weights["state_dict"]
|
278 |
+
save_file(weights, f"safetensors/{safetensors_name_2}.safetensors")
|
279 |
+
return "convert to safetensors done!"
|
280 |
+
|
281 |
+
def push_safetensors(model_to, token, branch):
|
282 |
+
try:
|
283 |
+
repo_exists = True
|
284 |
+
r_info = model_info(model_to, token=token)
|
285 |
+
except RepositoryNotFoundError:
|
286 |
+
repo_exists = False
|
287 |
+
finally:
|
288 |
+
if repo_exists:
|
289 |
+
print(r_info)
|
290 |
+
else:
|
291 |
+
create_repo(model_to, private=True, token=token)
|
292 |
+
try:
|
293 |
+
branch_exists = True
|
294 |
+
b_info = model_info(model_to, revision=branch, token=token)
|
295 |
+
except RevisionNotFoundError:
|
296 |
+
branch_exists = False
|
297 |
+
finally:
|
298 |
+
if branch_exists:
|
299 |
+
print(b_info)
|
300 |
+
else:
|
301 |
+
create_branch(model_to, branch=branch, token=token)
|
302 |
+
upload_folder(folder_path="safetensors", path_in_repo="", revision=branch, repo_id=model_to, commit_message=f"safetensors", token=token)
|
303 |
+
return "push safetensors done!"
|
304 |
+
|
305 |
+
def delete_safetensors():
|
306 |
+
os.system(f"rm -rf safetensors")
|
307 |
+
return "delete safetensors done!"
|
308 |
+
|
309 |
+
def download_safetensors(safetensors_url, safetensors_name):
|
310 |
+
# Create the safetensors directory if it doesn't exist
|
311 |
+
os.makedirs("safetensors", exist_ok=True)
|
312 |
+
|
313 |
+
if "drive.google.com" in safetensors_url:
|
314 |
+
gdown.download(url=safetensors_url, output=f"safetensors/{safetensors_name}.safetensors", quiet=False, fuzzy=True)
|
315 |
+
return "download safetensors done!"
|
316 |
+
elif "civitai.com" in safetensors_url:
|
317 |
+
os.system(f"aria2c --dir=safetensors/{safetensors_name}.safetensors --summary-interval=10 -c -x 10 -k 1M -s 10 {safetensors_url}")
|
318 |
+
return "download safetensors done!"
|
319 |
+
elif "huggingface.co" in safetensors_url:
|
320 |
+
os.system(f"aria2c --dir=safetensors/{safetensors_name}.safetensors --summary-interval=10 -c -x 10 -k 1M -s 10 {safetensors_url}")
|
321 |
+
return "download safetensors done!"
|
322 |
+
else:
|
323 |
+
try:
|
324 |
+
response = requests.get(safetensors_url)
|
325 |
+
if response.status_code == 200:
|
326 |
+
with open(f"safetensors/{safetensors_name}.safetensors", "wb") as f:
|
327 |
+
return "download safetensors done!"
|
328 |
+
else:
|
329 |
+
return "error download safetensors!"
|
330 |
+
except Exception as e:
|
331 |
+
return "error download safetensors!"
|
332 |
+
|
333 |
+
def from_safetensors_to_ckpt(safetensors_name, ckpt_name):
|
334 |
+
weights = load_file(f"safetensors/{safetensors_name}.safetensors", device="cpu")
|
335 |
+
os.system("mkdir ckpt")
|
336 |
+
torch.save(weights, f"ckpt/{ckpt_name}.ckpt")
|
337 |
+
return "convert to ckpt done!"
|
338 |
+
|
339 |
+
def delete_torrent():
|
340 |
+
os.system(f"rm -rf torrent")
|
341 |
+
return "delete torrent done!"
|
342 |
+
def delete_ckpt():
|
343 |
+
os.system(f"rm -rf ckpt")
|
344 |
+
return "delete ckpt done!"
|
345 |
+
|
346 |
+
def delete_pt():
|
347 |
+
os.system(f"rm -rf pt")
|
348 |
+
return "delete pt done!"
|
349 |
+
|
350 |
+
def delete_flax():
|
351 |
+
os.system(f"rm -rf flax")
|
352 |
+
return "delete flax done!"
|
353 |
+
|
354 |
+
def delete_safetensors():
|
355 |
+
os.system(f"rm -rf safetensors")
|
356 |
+
return "delete safetensors done!"
|
357 |
+
def delete_all():
|
358 |
+
delete_ckpt()
|
359 |
+
delete_torrent()
|
360 |
+
delete_pt()
|
361 |
+
delete_flax()
|
362 |
+
delete_safetensors()
|
363 |
+
return "delete all done!"
|
364 |
+
|
365 |
+
block = gr.Blocks()
|
366 |
+
|
367 |
+
with block:
|
368 |
+
|
369 |
+
gr.Markdown(
|
370 |
+
"""
|
371 |
+
|
372 |
+
## 🚨 Please first click all delete buttons 🚨 🎉<br />
|
373 |
+
## Almost all Download site link works<br />
|
374 |
+
### Special thanks to [@camenduru](https://huggingface.co/camenduru) for creating initial script <br />
|
375 |
+
### Modified By [@umair007](https://huggingface.co/umair007)<br />
|
376 |
+
|
377 |
+
""")
|
378 |
+
# Add delete buttons to the interface
|
379 |
+
with gr.Group():
|
380 |
+
with gr.Box():
|
381 |
+
with gr.Row().style(equal_height=True):
|
382 |
+
out_pt = gr.Textbox(show_label=False)
|
383 |
+
out_ckpt = gr.Textbox(show_label=False)
|
384 |
+
out_flax = gr.Textbox(show_label=False)
|
385 |
+
out_torrent = gr.Textbox(show_label=False)
|
386 |
+
out_safetensors = gr.Textbox(show_label=False)
|
387 |
+
out_delete_all = gr.Textbox(show_label=False)
|
388 |
+
with gr.Row().style(equal_height=True):
|
389 |
+
# Delete buttons
|
390 |
+
btn_delete_pt = gr.Button("delete pt")
|
391 |
+
btn_delete_torrent = gr.Button("Delete torrent")
|
392 |
+
btn_delete_ckpt = gr.Button("delete ckpt")
|
393 |
+
btn_delete_flax = gr.Button("delete flax")
|
394 |
+
btn_delete_safetensors = gr.Button("delete safetensors")
|
395 |
+
# Delete all button
|
396 |
+
btn_delete_all = gr.Button("delete all")
|
397 |
+
# Delete click
|
398 |
+
btn_delete_pt.click(delete_pt, outputs=out_pt)
|
399 |
+
btn_delete_ckpt.click(delete_ckpt, outputs=out_ckpt)
|
400 |
+
btn_delete_flax.click(delete_flax, outputs=out_flax)
|
401 |
+
btn_delete_safetensors.click(delete_safetensors, outputs=out_safetensors)
|
402 |
+
btn_delete_torrent.click(delete_torrent, outputs=out_torrent)
|
403 |
+
btn_delete_all.click(delete_all, outputs=out_delete_all)
|
404 |
+
|
405 |
+
gr.Markdown(
|
406 |
+
"""
|
407 |
+
### download and push file ckpt, yaml, safetensors etc <br />
|
408 |
+
file_url = https://civitai.com/api/download/models/4224 or https://huggingface.co/prompthero/openjourney/resolve/main/mdjrny-v4.ckpt or https://drive.google.com/file/d/file-id/view?usp=share_link<br />
|
409 |
+
file_name = openjourney.(extension_name) <br />
|
410 |
+
extension_name = ckpt, yaml, safetensors etc whatsever your file extension_name is <br />
|
411 |
+
ckpt_model_to = camenduru/openjourney <br />
|
412 |
+
branch = ckpt <br />
|
413 |
+
token = get from [https://huggingface.co/settings/tokens](https://huggingface.co/settings/tokens) new token role=write <br />
|
414 |
+
""")
|
415 |
+
with gr.Group():
|
416 |
+
with gr.Box():
|
417 |
+
with gr.Row().style(equal_height=True):
|
418 |
+
text_file_url_1 = gr.Textbox(show_label=False, max_lines=1, placeholder="file_url")
|
419 |
+
text_file_name_1 = gr.Textbox(show_label=False, max_lines=1, placeholder="file_name")
|
420 |
+
text_file_model_to = gr.Textbox(show_label=False, max_lines=1, placeholder="file_model_to")
|
421 |
+
text_file_branch = gr.Textbox(show_label=False, value="file", max_lines=1, placeholder="file_branch")
|
422 |
+
text_file_token = gr.Textbox(show_label=False, max_lines=1, placeholder="🤗 token")
|
423 |
+
out_file = gr.Textbox(show_label=False)
|
424 |
+
with gr.Row().style(equal_height=True):
|
425 |
+
btn_download_file = gr.Button("Download file")
|
426 |
+
btn_push_file_1 = gr.Button("Push file to 🤗")
|
427 |
+
btn_delete_file = gr.Button("Delete file")
|
428 |
+
btn_download_file.click(download_file, inputs=[text_file_url_1, text_file_name_1], outputs=out_file)
|
429 |
+
btn_push_file_1.click(push_file_1, inputs=[text_file_model_to, text_file_token, text_file_branch], outputs=out_file)
|
430 |
+
btn_delete_file.click(delete_file, outputs=out_file)
|
431 |
+
|
432 |
+
gr.Markdown(
|
433 |
+
"""
|
434 |
+
### download and push torrent file <br />
|
435 |
+
ckpt_url = example.com/file.torrent<br />
|
436 |
+
folder_name = openjourney <br />
|
437 |
+
ckpt_model_to = camenduru/openjourney <br />
|
438 |
+
branch = torrent <br />
|
439 |
+
token = get from [https://huggingface.co/settings/tokens](https://huggingface.co/settings/tokens) new token role=write <br />
|
440 |
+
""")
|
441 |
+
with gr.Group():
|
442 |
+
with gr.Box():
|
443 |
+
with gr.Row().style(equal_height=True):
|
444 |
+
text_torrent_url = gr.Textbox(show_label=False, max_lines=1, placeholder="torrent_url")
|
445 |
+
text_torrent_model_to = gr.Textbox(show_label=False, max_lines=1, placeholder="torrent_model_to")
|
446 |
+
text_torrent_branch = gr.Textbox(show_label=False, value="torrent", max_lines=1, placeholder="torrent_branch")
|
447 |
+
text_torrent_token = gr.Textbox(show_label=False, max_lines=1, placeholder="🤗 token")
|
448 |
+
out_torrent = gr.Textbox(show_label=False)
|
449 |
+
with gr.Row().style(equal_height=True):
|
450 |
+
btn_download_torrent = gr.Button("Download torrent")
|
451 |
+
btn_push_torrent = gr.Button("Push torrent to 🤗")
|
452 |
+
btn_delete_torrent = gr.Button("Delete torrent")
|
453 |
+
btn_download_torrent.click(download_torrent, inputs=[text_torrent_url], outputs=out_torrent)
|
454 |
+
btn_push_torrent.click(push_torrent, inputs=[text_torrent_model_to, text_torrent_token, text_torrent_branch], outputs=out_torrent)
|
455 |
+
btn_delete_torrent.click(delete_torrent, outputs=out_torrent)
|
456 |
+
|
457 |
+
gr.Markdown(
|
458 |
+
"""
|
459 |
+
### ckpt to pytorch
|
460 |
+
ckpt_url = https://civitai.com/api/download/models/4224 or https://huggingface.co/prompthero/openjourney/resolve/main/mdjrny-v4.ckpt or https://drive.google.com/file/d/file-id/view?usp=share_link<br />
|
461 |
+
pt_model_to = camenduru/openjourney <br />
|
462 |
+
branch = main <br />
|
463 |
+
token = get from [https://huggingface.co/settings/tokens](https://huggingface.co/settings/tokens) new token role=write
|
464 |
+
""")
|
465 |
+
|
466 |
+
with gr.Group():
|
467 |
+
with gr.Box():
|
468 |
+
with gr.Row().style(equal_height=True):
|
469 |
+
text_ckpt_url = gr.Textbox(show_label=False, max_lines=1, placeholder="ckpt_url")
|
470 |
+
text_pt_model_to = gr.Textbox(show_label=False, max_lines=1, placeholder="pt_model_to")
|
471 |
+
text_pt_branch = gr.Textbox(show_label=False, value="main", max_lines=1, placeholder="branch")
|
472 |
+
text_pt_token = gr.Textbox(show_label=False, max_lines=1, placeholder="🤗 token")
|
473 |
+
out_pt = gr.Textbox(show_label=False)
|
474 |
+
with gr.Row().style(equal_height=True):
|
475 |
+
btn_download_ckpt = gr.Button("Download CKPT")
|
476 |
+
btn_to_pt = gr.Button("Convert to PT")
|
477 |
+
btn_push_pt = gr.Button("Push PT to 🤗")
|
478 |
+
btn_delete_pt = gr.Button("Delete PT")
|
479 |
+
btn_download_ckpt.click(download_ckpt, inputs=[text_ckpt_url], outputs=out_pt)
|
480 |
+
btn_to_pt.click(to_pt, outputs=out_pt)
|
481 |
+
btn_push_pt.click(push_pt, inputs=[text_pt_model_to, text_pt_token, text_pt_branch], outputs=out_pt)
|
482 |
+
btn_delete_pt.click(delete_pt, outputs=out_pt)
|
483 |
+
gr.Markdown(
|
484 |
+
"""
|
485 |
+
### pytorch to flax <br />
|
486 |
+
pt_model_from = prompthero/openjourney <br />
|
487 |
+
flax_model_to = camenduru/openjourney <br />
|
488 |
+
branch = flax <br />
|
489 |
+
token = get from [https://huggingface.co/settings/tokens](https://huggingface.co/settings/tokens) new token role=write <br />
|
490 |
+
""")
|
491 |
+
|
492 |
+
with gr.Group():
|
493 |
+
with gr.Box():
|
494 |
+
with gr.Row().style(equal_height=True):
|
495 |
+
text_pt_model_from = gr.Textbox(show_label=False, max_lines=1, placeholder="pt_model_from")
|
496 |
+
text_flax_model_to = gr.Textbox(show_label=False, max_lines=1, placeholder="flax_model_to")
|
497 |
+
text_flax_branch = gr.Textbox(show_label=False, value="flax", max_lines=1, placeholder="flax_branch")
|
498 |
+
text_flax_token = gr.Textbox(show_label=False, max_lines=1, placeholder="🤗 token")
|
499 |
+
out_flax = gr.Textbox(show_label=False)
|
500 |
+
with gr.Row().style(equal_height=True):
|
501 |
+
btn_clone_pt = gr.Button("Clone PT from 🤗")
|
502 |
+
btn_to_flax = gr.Button("Convert to Flax")
|
503 |
+
btn_push_flax = gr.Button("Push Flax to 🤗")
|
504 |
+
btn_delete_flax = gr.Button("Delete Flax")
|
505 |
+
btn_clone_pt.click(clone_pt, inputs=[text_pt_model_from], outputs=out_flax)
|
506 |
+
btn_to_flax.click(to_flax, outputs=out_flax)
|
507 |
+
btn_push_flax.click(push_flax, inputs=[text_flax_model_to, text_flax_token, text_flax_branch], outputs=out_flax)
|
508 |
+
btn_delete_flax.click(delete_flax, outputs=out_flax)
|
509 |
+
|
510 |
+
gr.Markdown(
|
511 |
+
"""
|
512 |
+
### pytorch to ckpt
|
513 |
+
pt_model_from = prompthero/openjourney <br />
|
514 |
+
ckpt_name = openjourney <br />
|
515 |
+
ckpt_model_to = camenduru/openjourney <br />
|
516 |
+
branch = ckpt <br />
|
517 |
+
token = get from [https://huggingface.co/settings/tokens](https://huggingface.co/settings/tokens) new token role=write
|
518 |
+
""")
|
519 |
+
with gr.Group():
|
520 |
+
with gr.Box():
|
521 |
+
with gr.Row().style(equal_height=True):
|
522 |
+
text_pt_model_from = gr.Textbox(show_label=False, max_lines=1, placeholder="pt_model_from")
|
523 |
+
text_ckpt_name = gr.Textbox(show_label=False, max_lines=1, placeholder="ckpt_name")
|
524 |
+
text_ckpt_model_to = gr.Textbox(show_label=False, max_lines=1, placeholder="ckpt_model_to")
|
525 |
+
text_ckpt_branch = gr.Textbox(show_label=False, value="ckpt", max_lines=1, placeholder="ckpt_branch")
|
526 |
+
text_ckpt_token = gr.Textbox(show_label=False, max_lines=1, placeholder="🤗 token")
|
527 |
+
out_ckpt = gr.Textbox(show_label=False)
|
528 |
+
with gr.Row().style(equal_height=True):
|
529 |
+
btn_clone_pt = gr.Button("Clone PT from 🤗")
|
530 |
+
btn_to_ckpt = gr.Button("Convert to CKPT")
|
531 |
+
btn_push_ckpt = gr.Button("Push CKPT to 🤗")
|
532 |
+
btn_delete_ckpt = gr.Button("Delete CKPT")
|
533 |
+
btn_clone_pt.click(clone_pt, inputs=[text_pt_model_from], outputs=out_ckpt)
|
534 |
+
btn_to_ckpt.click(to_ckpt, inputs=[text_ckpt_name], outputs=out_ckpt)
|
535 |
+
btn_push_ckpt.click(push_ckpt, inputs=[text_ckpt_model_to, text_ckpt_token, text_ckpt_branch], outputs=out_ckpt)
|
536 |
+
btn_delete_ckpt.click(delete_ckpt, outputs=out_ckpt)
|
537 |
+
gr.Markdown(
|
538 |
+
"""
|
539 |
+
### ckpt to safetensors <br />
|
540 |
+
ckpt_url = https://civitai.com/api/download/models/4224 or https://huggingface.co/prompthero/openjourney/resolve/main/mdjrny-v4.ckpt or https://drive.google.com/file/d/file-id/view?usp=share_link<br />
|
541 |
+
safetensors_name = openjourney <br />
|
542 |
+
safetensors_model_to = camenduru/openjourney <br />
|
543 |
+
branch = safetensors <br />
|
544 |
+
token = get from [https://huggingface.co/settings/tokens](https://huggingface.co/settings/tokens) new token role=write <br />
|
545 |
+
""")
|
546 |
+
with gr.Group():
|
547 |
+
with gr.Box():
|
548 |
+
with gr.Row().style(equal_height=True):
|
549 |
+
text_ckpt_url_2 = gr.Textbox(show_label=False, max_lines=1, placeholder="ckpt_url_2")
|
550 |
+
text_ckpt_name_2 = gr.Textbox(show_label=False, max_lines=1, placeholder="ckpt_name_2")
|
551 |
+
text_safetensors_name_2 = gr.Textbox(show_label=False, max_lines=1, placeholder="safetensors_name_2")
|
552 |
+
text_safetensors_model_to = gr.Textbox(show_label=False, max_lines=1, placeholder="safetensors_model_to")
|
553 |
+
text_safetensors_branch = gr.Textbox(show_label=False, value="safetensors", max_lines=1, placeholder="safetensors_branch")
|
554 |
+
text_safetensors_token = gr.Textbox(show_label=False, max_lines=1, placeholder="🤗 token")
|
555 |
+
out_safetensors = gr.Textbox(show_label=False)
|
556 |
+
with gr.Row().style(equal_height=True):
|
557 |
+
btn_download_ckpt = gr.Button("Download CKPT")
|
558 |
+
btn_to_safetensors = gr.Button("Convert to Safetensors")
|
559 |
+
btn_push_safetensors = gr.Button("Push Safetensors to 🤗")
|
560 |
+
btn_delete_safetensors = gr.Button("Delete Safetensors")
|
561 |
+
btn_download_ckpt.click(download_ckpt, inputs=[text_ckpt_url_2, text_ckpt_name_2], outputs=out_safetensors)
|
562 |
+
btn_to_safetensors.click(to_safetensors, inputs=[text_ckpt_name_2, text_safetensors_name_2], outputs=out_safetensors)
|
563 |
+
btn_push_safetensors.click(push_safetensors, inputs=[text_safetensors_model_to, text_safetensors_token, text_safetensors_branch], outputs=out_safetensors)
|
564 |
+
btn_delete_safetensors.click(delete_safetensors, outputs=out_safetensors)
|
565 |
+
gr.Markdown(
|
566 |
+
"""
|
567 |
+
### safetensors to ckpt <br />
|
568 |
+
safetensors_url = https://civitai.com/api/download/models/4224 or https://huggingface.co/prompthero/openjourney/resolve/main/mdjrny-v4.ckpt or https://drive.google.com/file/d/file-id/view?usp=share_link<br />
|
569 |
+
ckpt_name = openjourney <br />
|
570 |
+
ckpt_model_to = camenduru/openjourney <br />
|
571 |
+
branch = ckpt <br />
|
572 |
+
token = get from [https://huggingface.co/settings/tokens](https://huggingface.co/settings/tokens) new token role=write <br />
|
573 |
+
""")
|
574 |
+
with gr.Group():
|
575 |
+
with gr.Box():
|
576 |
+
with gr.Row().style(equal_height=True):
|
577 |
+
text_safetensors_url = gr.Textbox(show_label=False, max_lines=1, placeholder="safetensors_url")
|
578 |
+
text_safetensors_name = gr.Textbox(show_label=False, max_lines=1, placeholder="safetensors_name")
|
579 |
+
text_safetensors_to_ckpt_name = gr.Textbox(show_label=False, max_lines=1, placeholder="ckpt_name")
|
580 |
+
text_safetensors_to_ckpt_model_to = gr.Textbox(show_label=False, max_lines=1, placeholder="ckpt_model_to")
|
581 |
+
text_safetensors_to_ckpt_branch = gr.Textbox(show_label=False, value="ckpt", max_lines=1, placeholder="ckpt_branch")
|
582 |
+
text_safetensors_to_ckpt_token = gr.Textbox(show_label=False, max_lines=1, placeholder="🤗 token")
|
583 |
+
out_safetensors_to_ckpt = gr.Textbox(show_label=False)
|
584 |
+
with gr.Row().style(equal_height=True):
|
585 |
+
btn_download_safetensors = gr.Button("Download Safetensors")
|
586 |
+
btn_safetensors_to_ckpt = gr.Button("Convert to CKPT")
|
587 |
+
btn_push_safetensors_to_ckpt = gr.Button("Push CKPT to 🤗")
|
588 |
+
btn_delete_safetensors_ckpt = gr.Button("Delete CKPT")
|
589 |
+
btn_download_safetensors.click(download_safetensors, inputs=[text_safetensors_url, text_safetensors_name], outputs=out_safetensors_to_ckpt)
|
590 |
+
btn_safetensors_to_ckpt.click(from_safetensors_to_ckpt, inputs=[text_safetensors_name, text_safetensors_to_ckpt_name], outputs=out_safetensors_to_ckpt)
|
591 |
+
btn_push_safetensors_to_ckpt.click(push_ckpt, inputs=[text_safetensors_to_ckpt_model_to, text_safetensors_to_ckpt_token, text_safetensors_to_ckpt_branch], outputs=out_safetensors_to_ckpt)
|
592 |
+
btn_delete_safetensors_ckpt.click(delete_ckpt, outputs=out_safetensors_to_ckpt)
|
593 |
+
|
594 |
+
|
595 |
+
block.launch()
|
packages.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
aria2
|
requirements.txt
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
jax[cpu]
|
2 |
+
flax
|
3 |
+
git+https://github.com/huggingface/diffusers
|
4 |
+
accelerate
|
5 |
+
transformers
|
6 |
+
ftfy
|
7 |
+
OmegaConf
|
8 |
+
huggingface-hub==0.11.0
|
9 |
+
torch
|
10 |
+
safetensors
|
11 |
+
gdown
|
12 |
+
requests
|
13 |
+
aria2p
|