Spaces:
Build error
Build error
Commit
·
f93ba0b
0
Parent(s):
Duplicate from umair007/converter
Browse files- .gitattributes +34 -0
- README.md +12 -0
- app.py +508 -0
- requirements.txt +12 -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/converter
|
12 |
+
---
|
app.py
ADDED
@@ -0,0 +1,508 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os, gdown
|
2 |
+
import requests
|
3 |
+
import numpy as np
|
4 |
+
import gradio as gr
|
5 |
+
from diffusers import FlaxStableDiffusionPipeline
|
6 |
+
import torch
|
7 |
+
from safetensors.torch import save_file, load_file
|
8 |
+
from huggingface_hub import model_info, create_repo, create_branch, upload_folder
|
9 |
+
from huggingface_hub.utils import RepositoryNotFoundError, RevisionNotFoundError
|
10 |
+
|
11 |
+
def download_ckpt(ckpt_url_1, ckpt_name_1):
|
12 |
+
# Create the ckpt directory if it doesn't exist
|
13 |
+
os.makedirs("ckpt", exist_ok=True)
|
14 |
+
|
15 |
+
if "drive.google.com" in ckpt_url_1:
|
16 |
+
gdown.download(url=ckpt_url_1, output=f"ckpt/{ckpt_name_1}.ckpt", quiet=False, fuzzy=True)
|
17 |
+
return "download ckpt done!"
|
18 |
+
elif "civitai.com" in ckpt_url_1:
|
19 |
+
os.system(f"wget {ckpt_url_1} --content-disposition -O ckpt/{ckpt_name_1}.ckpt")
|
20 |
+
return "download ckpt done!"
|
21 |
+
elif "huggingface.co" in ckpt_url_1:
|
22 |
+
os.system(f"wget {ckpt_url_1} -O ckpt/{ckpt_name_1}.ckpt")
|
23 |
+
return "download ckpt done!"
|
24 |
+
else:
|
25 |
+
try:
|
26 |
+
response = requests.get(ckpt_url_1)
|
27 |
+
if response.status_code == 200:
|
28 |
+
with open(f"ckpt/{ckpt_name_1}.ckpt", "wb") as f:
|
29 |
+
return "download ckpt done!"
|
30 |
+
else:
|
31 |
+
return "error download ckpt!"
|
32 |
+
except Exception as e:
|
33 |
+
return "error download ckpt!"
|
34 |
+
|
35 |
+
|
36 |
+
def push_ckpt_1(model_to, token, branch):
|
37 |
+
try:
|
38 |
+
repo_exists = True
|
39 |
+
r_info = model_info(model_to, token=token)
|
40 |
+
except RepositoryNotFoundError:
|
41 |
+
repo_exists = False
|
42 |
+
finally:
|
43 |
+
if repo_exists:
|
44 |
+
print(r_info)
|
45 |
+
else:
|
46 |
+
create_repo(model_to, private=True, token=token)
|
47 |
+
try:
|
48 |
+
branch_exists = True
|
49 |
+
b_info = model_info(model_to, revision=branch, token=token)
|
50 |
+
except RevisionNotFoundError:
|
51 |
+
branch_exists = False
|
52 |
+
finally:
|
53 |
+
if branch_exists:
|
54 |
+
print(b_info)
|
55 |
+
else:
|
56 |
+
create_branch(model_to, branch=branch, token=token)
|
57 |
+
# Create the ckpt directory if it doesn't exist
|
58 |
+
os.makedirs("ckpt", exist_ok=True)
|
59 |
+
upload_folder(folder_path="ckpt", path_in_repo="", revision=branch, repo_id=model_to, commit_message=f"ckpt", token=token)
|
60 |
+
return "push ckpt done!"
|
61 |
+
|
62 |
+
def delete_ckpt():
|
63 |
+
os.system(f"rm -rf ckpt")
|
64 |
+
return "delete ckpt done!"
|
65 |
+
|
66 |
+
def download_ckpt(ckpt_url, ckpt_name):
|
67 |
+
# Create the ckpt directory if it doesn't exist
|
68 |
+
os.makedirs("ckpt", exist_ok=True)
|
69 |
+
|
70 |
+
if "drive.google.com" in ckpt_url:
|
71 |
+
gdown.download(url=ckpt_url, output=f"ckpt/{ckpt_name}.ckpt", quiet=False, fuzzy=True)
|
72 |
+
return "download ckpt done!"
|
73 |
+
elif "civitai.com" in ckpt_url:
|
74 |
+
os.system(f"wget {ckpt_url} --content-disposition -O ckpt/{ckpt_name}.ckpt")
|
75 |
+
return "download ckpt done!"
|
76 |
+
elif "huggingface.co" in ckpt_url:
|
77 |
+
os.system(f"wget {ckpt_url} -O ckpt/{ckpt_name}.ckpt")
|
78 |
+
return "download ckpt done!"
|
79 |
+
else:
|
80 |
+
try:
|
81 |
+
response = requests.get(ckpt_url)
|
82 |
+
if response.status_code == 200:
|
83 |
+
with open(f"ckpt/{ckpt_name}.ckpt", "wb") as f:
|
84 |
+
return "download ckpt done!"
|
85 |
+
else:
|
86 |
+
return "error download ckpt!"
|
87 |
+
except Exception as e:
|
88 |
+
return "error download ckpt!"
|
89 |
+
|
90 |
+
|
91 |
+
def to_pt():
|
92 |
+
os.system("wget -q https://raw.githubusercontent.com/huggingface/diffusers/main/scripts/convert_original_stable_diffusion_to_diffusers.py")
|
93 |
+
os.system(f"python3 convert_original_stable_diffusion_to_diffusers.py --checkpoint_path model.ckpt --dump_path pt")
|
94 |
+
return "convert to pt done!"
|
95 |
+
|
96 |
+
def push_pt(model_to, token, branch):
|
97 |
+
try:
|
98 |
+
repo_exists = True
|
99 |
+
r_info = model_info(model_to, token=token)
|
100 |
+
except RepositoryNotFoundError:
|
101 |
+
repo_exists = False
|
102 |
+
finally:
|
103 |
+
if repo_exists:
|
104 |
+
print(r_info)
|
105 |
+
else:
|
106 |
+
create_repo(model_to, private=True, token=token)
|
107 |
+
try:
|
108 |
+
branch_exists = True
|
109 |
+
b_info = model_info(model_to, revision=branch, token=token)
|
110 |
+
except RevisionNotFoundError:
|
111 |
+
branch_exists = False
|
112 |
+
finally:
|
113 |
+
if branch_exists:
|
114 |
+
print(b_info)
|
115 |
+
else:
|
116 |
+
create_branch(model_to, branch=branch, token=token)
|
117 |
+
upload_folder(folder_path="pt", path_in_repo="", revision=branch, repo_id=model_to, commit_message=f"pt", token=token)
|
118 |
+
return "push pt done!"
|
119 |
+
|
120 |
+
def delete_pt():
|
121 |
+
os.system(f"rm -rf pt")
|
122 |
+
return "delete pt done!"
|
123 |
+
|
124 |
+
def clone_pt(model_url):
|
125 |
+
os.system("git lfs install")
|
126 |
+
os.system(f"git clone https://huggingface.co/{model_url} pt")
|
127 |
+
return "clone pt done!"
|
128 |
+
|
129 |
+
def to_flax():
|
130 |
+
pipe, params = FlaxStableDiffusionPipeline.from_pretrained("pt", from_pt=True)
|
131 |
+
pipe.save_pretrained("flax", params=params)
|
132 |
+
return "convert to flax done!"
|
133 |
+
|
134 |
+
def push_flax(model_to, token, branch):
|
135 |
+
try:
|
136 |
+
repo_exists = True
|
137 |
+
r_info = model_info(model_to, token=token)
|
138 |
+
except RepositoryNotFoundError:
|
139 |
+
repo_exists = False
|
140 |
+
finally:
|
141 |
+
if repo_exists:
|
142 |
+
print(r_info)
|
143 |
+
else:
|
144 |
+
create_repo(model_to, private=True, token=token)
|
145 |
+
try:
|
146 |
+
branch_exists = True
|
147 |
+
b_info = model_info(model_to, revision=branch, token=token)
|
148 |
+
except RevisionNotFoundError:
|
149 |
+
branch_exists = False
|
150 |
+
finally:
|
151 |
+
if branch_exists:
|
152 |
+
print(b_info)
|
153 |
+
else:
|
154 |
+
create_branch(model_to, branch=branch, token=token)
|
155 |
+
upload_folder(folder_path="flax", path_in_repo="", revision=branch, repo_id=model_to, commit_message=f"flax", token=token)
|
156 |
+
return "push flax done!"
|
157 |
+
|
158 |
+
def delete_flax():
|
159 |
+
os.system(f"rm -rf flax")
|
160 |
+
return "delete flax done!"
|
161 |
+
|
162 |
+
def to_ckpt(ckpt_name):
|
163 |
+
os.system("wget -q https://raw.githubusercontent.com/huggingface/diffusers/main/scripts/convert_diffusers_to_original_stable_diffusion.py")
|
164 |
+
os.system("mkdir ckpt")
|
165 |
+
os.system(f"python3 convert_diffusers_to_original_stable_diffusion.py --model_path pt --checkpoint_path ckpt/{ckpt_name}.ckpt")
|
166 |
+
return "convert to ckpt done!"
|
167 |
+
|
168 |
+
def push_ckpt(model_to, token, branch):
|
169 |
+
try:
|
170 |
+
repo_exists = True
|
171 |
+
r_info = model_info(model_to, token=token)
|
172 |
+
except RepositoryNotFoundError:
|
173 |
+
repo_exists = False
|
174 |
+
finally:
|
175 |
+
if repo_exists:
|
176 |
+
print(r_info)
|
177 |
+
else:
|
178 |
+
create_repo(model_to, private=True, token=token)
|
179 |
+
try:
|
180 |
+
branch_exists = True
|
181 |
+
b_info = model_info(model_to, revision=branch, token=token)
|
182 |
+
except RevisionNotFoundError:
|
183 |
+
branch_exists = False
|
184 |
+
finally:
|
185 |
+
if branch_exists:
|
186 |
+
print(b_info)
|
187 |
+
else:
|
188 |
+
create_branch(model_to, branch=branch, token=token)
|
189 |
+
upload_folder(folder_path="ckpt", path_in_repo="", revision=branch, repo_id=model_to, commit_message=f"ckpt", token=token)
|
190 |
+
return "push ckpt done!"
|
191 |
+
|
192 |
+
def delete_ckpt():
|
193 |
+
os.system(f"rm -rf ckpt")
|
194 |
+
return "delete ckpt done!"
|
195 |
+
|
196 |
+
def download_ckpt(ckpt_url_2, ckpt_name_2):
|
197 |
+
# Create the ckpt directory if it doesn't exist
|
198 |
+
os.makedirs("ckpt", exist_ok=True)
|
199 |
+
|
200 |
+
if "drive.google.com" in ckpt_url_2:
|
201 |
+
gdown.download(url=ckpt_url_2, output=f"ckpt/{ckpt_name_2}.ckpt", quiet=False, fuzzy=True)
|
202 |
+
return "download ckpt done!"
|
203 |
+
elif "civitai.com" in ckpt_url_2:
|
204 |
+
os.system(f"wget {ckpt_url_2} --content-disposition -O ckpt/{ckpt_name_2}.ckpt")
|
205 |
+
return "download ckpt done!"
|
206 |
+
elif "huggingface.co" in ckpt_url_2:
|
207 |
+
os.system(f"wget {ckpt_url_2} -O ckpt/{ckpt_name_2}.ckpt")
|
208 |
+
return "download ckpt done!"
|
209 |
+
else:
|
210 |
+
try:
|
211 |
+
response = requests.get(ckpt_url_2)
|
212 |
+
if response.status_code == 200:
|
213 |
+
with open(f"ckpt/{ckpt_name_2}.ckpt", "wb") as f:
|
214 |
+
return "download ckpt done!"
|
215 |
+
else:
|
216 |
+
return "error download ckpt!"
|
217 |
+
except Exception as e:
|
218 |
+
return "error download ckpt!"
|
219 |
+
|
220 |
+
|
221 |
+
def to_safetensors(safetensors_name_2):
|
222 |
+
os.system("mkdir safetensors")
|
223 |
+
weights = torch.load(f"ckpt/{ckpt_name_2}.ckpt")
|
224 |
+
if "state_dict" in weights:
|
225 |
+
weights = weights["state_dict"]
|
226 |
+
save_file(weights, f"safetensors/{safetensors_name_2}.safetensors")
|
227 |
+
return "convert to safetensors done!"
|
228 |
+
|
229 |
+
def push_safetensors(model_to, token, branch):
|
230 |
+
try:
|
231 |
+
repo_exists = True
|
232 |
+
r_info = model_info(model_to, token=token)
|
233 |
+
except RepositoryNotFoundError:
|
234 |
+
repo_exists = False
|
235 |
+
finally:
|
236 |
+
if repo_exists:
|
237 |
+
print(r_info)
|
238 |
+
else:
|
239 |
+
create_repo(model_to, private=True, token=token)
|
240 |
+
try:
|
241 |
+
branch_exists = True
|
242 |
+
b_info = model_info(model_to, revision=branch, token=token)
|
243 |
+
except RevisionNotFoundError:
|
244 |
+
branch_exists = False
|
245 |
+
finally:
|
246 |
+
if branch_exists:
|
247 |
+
print(b_info)
|
248 |
+
else:
|
249 |
+
create_branch(model_to, branch=branch, token=token)
|
250 |
+
upload_folder(folder_path="safetensors", path_in_repo="", revision=branch, repo_id=model_to, commit_message=f"safetensors", token=token)
|
251 |
+
return "push safetensors done!"
|
252 |
+
|
253 |
+
def delete_safetensors():
|
254 |
+
os.system(f"rm -rf safetensors")
|
255 |
+
return "delete safetensors done!"
|
256 |
+
|
257 |
+
def download_safetensors(safetensors_url, safetensors_name):
|
258 |
+
# Create the safetensors directory if it doesn't exist
|
259 |
+
os.makedirs("safetensors", exist_ok=True)
|
260 |
+
|
261 |
+
if "drive.google.com" in safetensors_url:
|
262 |
+
gdown.download(url=safetensors_url, output=f"safetensors/{safetensors_name}.safetensors", quiet=False, fuzzy=True)
|
263 |
+
return "download safetensors done!"
|
264 |
+
elif "civitai.com" in safetensors_url:
|
265 |
+
os.system(f"wget {safetensors_url} --content-disposition -O safetensors/{safetensors_name}.safetensors")
|
266 |
+
return "download safetensors done!"
|
267 |
+
elif "huggingface.co" in safetensors_url:
|
268 |
+
os.system(f"wget {safetensors_url} -O safetensors/{safetensors_name}.safetensors")
|
269 |
+
return "download safetensors done!"
|
270 |
+
else:
|
271 |
+
try:
|
272 |
+
response = requests.get(safetensors_url)
|
273 |
+
if response.status_code == 200:
|
274 |
+
with open(f"safetensors/{safetensors_name}.safetensors", "wb") as f:
|
275 |
+
return "download safetensors done!"
|
276 |
+
else:
|
277 |
+
return "error download safetensors!"
|
278 |
+
except Exception as e:
|
279 |
+
return "error download safetensors!"
|
280 |
+
|
281 |
+
def from_safetensors_to_ckpt(ckpt_name):
|
282 |
+
weights = load_file(f"safetensors/{safetensors_name}.safetensors", device="cpu")
|
283 |
+
os.system("mkdir ckpt")
|
284 |
+
torch.save(weights, f"ckpt/{ckpt_name}.ckpt")
|
285 |
+
return "convert to ckpt done!"
|
286 |
+
|
287 |
+
def delete_ckpt():
|
288 |
+
os.system(f"rm -rf ckpt")
|
289 |
+
return "delete ckpt done!"
|
290 |
+
|
291 |
+
def delete_pt():
|
292 |
+
os.system(f"rm -rf pt")
|
293 |
+
return "delete pt done!"
|
294 |
+
|
295 |
+
def delete_flax():
|
296 |
+
os.system(f"rm -rf flax")
|
297 |
+
return "delete flax done!"
|
298 |
+
|
299 |
+
def delete_safetensors():
|
300 |
+
os.system(f"rm -rf safetensors")
|
301 |
+
return "delete safetensors done!"
|
302 |
+
def delete_all():
|
303 |
+
delete_ckpt()
|
304 |
+
delete_pt()
|
305 |
+
delete_flax()
|
306 |
+
delete_safetensors()
|
307 |
+
return "delete all done!"
|
308 |
+
|
309 |
+
block = gr.Blocks()
|
310 |
+
|
311 |
+
with block:
|
312 |
+
|
313 |
+
gr.Markdown(
|
314 |
+
"""
|
315 |
+
|
316 |
+
## 🚨 Please first click all delete buttons 🚨 🎉<br />
|
317 |
+
## Almost all Download site link works<br />
|
318 |
+
### Special thanks to [@camenduru](https://huggingface.co/camenduru) for creating initial script <br />
|
319 |
+
### Modified By [@umair007](https://huggingface.co/umair007)<br />
|
320 |
+
|
321 |
+
""")
|
322 |
+
# Add delete buttons to the interface
|
323 |
+
with gr.Group():
|
324 |
+
with gr.Box():
|
325 |
+
with gr.Row().style(equal_height=True):
|
326 |
+
out_pt = gr.Textbox(show_label=False)
|
327 |
+
out_ckpt = gr.Textbox(show_label=False)
|
328 |
+
out_flax = gr.Textbox(show_label=False)
|
329 |
+
out_safetensors = gr.Textbox(show_label=False)
|
330 |
+
out_delete_all = gr.Textbox(show_label=False)
|
331 |
+
with gr.Row().style(equal_height=True):
|
332 |
+
# Delete buttons
|
333 |
+
btn_delete_pt = gr.Button("delete pt")
|
334 |
+
btn_delete_ckpt = gr.Button("delete ckpt")
|
335 |
+
btn_delete_flax = gr.Button("delete flax")
|
336 |
+
btn_delete_safetensors = gr.Button("delete safetensors")
|
337 |
+
# Delete all button
|
338 |
+
btn_delete_all = gr.Button("delete all")
|
339 |
+
# Delete click
|
340 |
+
btn_delete_pt.click(delete_pt, outputs=out_pt)
|
341 |
+
btn_delete_ckpt.click(delete_ckpt, outputs=out_ckpt)
|
342 |
+
btn_delete_flax.click(delete_flax, outputs=out_flax)
|
343 |
+
btn_delete_safetensors.click(delete_safetensors, outputs=out_safetensors)
|
344 |
+
btn_delete_all.click(delete_all, outputs=out_delete_all)
|
345 |
+
|
346 |
+
gr.Markdown(
|
347 |
+
"""
|
348 |
+
### download and push ckpt <br />
|
349 |
+
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 />
|
350 |
+
ckpt_name = openjourney <br />
|
351 |
+
ckpt_model_to = camenduru/openjourney <br />
|
352 |
+
branch = ckpt <br />
|
353 |
+
token = get from [https://huggingface.co/settings/tokens](https://huggingface.co/settings/tokens) new token role=write <br />
|
354 |
+
""")
|
355 |
+
with gr.Group():
|
356 |
+
with gr.Box():
|
357 |
+
with gr.Row().style(equal_height=True):
|
358 |
+
text_ckpt_url_1 = gr.Textbox(show_label=False, max_lines=1, placeholder="ckpt_url_1")
|
359 |
+
text_ckpt_name_1 = gr.Textbox(show_label=False, max_lines=1, placeholder="ckpt_name_1")
|
360 |
+
text_ckpt_model_to = gr.Textbox(show_label=False, max_lines=1, placeholder="ckpt_model_to")
|
361 |
+
text_ckpt_branch = gr.Textbox(show_label=False, value="ckpt", max_lines=1, placeholder="ckpt_branch")
|
362 |
+
text_ckpt_token = gr.Textbox(show_label=False, max_lines=1, placeholder="🤗 token")
|
363 |
+
out_ckpt = gr.Textbox(show_label=False)
|
364 |
+
with gr.Row().style(equal_height=True):
|
365 |
+
btn_download_ckpt = gr.Button("Download CKPT")
|
366 |
+
btn_push_ckpt_1 = gr.Button("Push CKPT to 🤗")
|
367 |
+
btn_delete_ckpt = gr.Button("Delete CKPT")
|
368 |
+
btn_download_ckpt.click(download_ckpt, inputs=[text_ckpt_url_1, text_ckpt_name_1], outputs=out_ckpt)
|
369 |
+
btn_push_ckpt_1.click(push_ckpt_1, inputs=[text_ckpt_model_to, text_ckpt_token, text_ckpt_branch], outputs=out_ckpt)
|
370 |
+
btn_delete_ckpt.click(delete_ckpt, outputs=out_ckpt)
|
371 |
+
|
372 |
+
gr.Markdown(
|
373 |
+
"""
|
374 |
+
## 🚨 Please first click all delete buttons 🚨 Thanks to 🤗 ❤ Now with CPU Upgrade! 🎉
|
375 |
+
### ckpt to pytorch
|
376 |
+
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 />
|
377 |
+
pt_model_to = camenduru/openjourney <br />
|
378 |
+
branch = main <br />
|
379 |
+
token = get from [https://huggingface.co/settings/tokens](https://huggingface.co/settings/tokens) new token role=write
|
380 |
+
""")
|
381 |
+
with gr.Group():
|
382 |
+
with gr.Box():
|
383 |
+
with gr.Row().style(equal_height=True):
|
384 |
+
text_ckpt_url = gr.Textbox(show_label=False, max_lines=1, placeholder="ckpt_url")
|
385 |
+
text_pt_model_to = gr.Textbox(show_label=False, max_lines=1, placeholder="pt_model_to")
|
386 |
+
text_pt_branch = gr.Textbox(show_label=False, value="main", max_lines=1, placeholder="branch")
|
387 |
+
text_pt_token = gr.Textbox(show_label=False, max_lines=1, placeholder="🤗 token")
|
388 |
+
out_pt = gr.Textbox(show_label=False)
|
389 |
+
with gr.Row().style(equal_height=True):
|
390 |
+
btn_download_ckpt = gr.Button("Download CKPT")
|
391 |
+
btn_to_pt = gr.Button("Convert to PT")
|
392 |
+
btn_push_pt = gr.Button("Push PT to 🤗")
|
393 |
+
btn_delete_pt = gr.Button("Delete PT")
|
394 |
+
btn_download_ckpt.click(download_ckpt, inputs=[text_ckpt_url], outputs=out_pt)
|
395 |
+
btn_to_pt.click(to_pt, outputs=out_pt)
|
396 |
+
btn_push_pt.click(push_pt, inputs=[text_pt_model_to, text_pt_token, text_pt_branch], outputs=out_pt)
|
397 |
+
btn_delete_pt.click(delete_pt, outputs=out_pt)
|
398 |
+
gr.Markdown(
|
399 |
+
"""
|
400 |
+
### pytorch to flax <br />
|
401 |
+
pt_model_from = prompthero/openjourney <br />
|
402 |
+
flax_model_to = camenduru/openjourney <br />
|
403 |
+
branch = flax <br />
|
404 |
+
token = get from [https://huggingface.co/settings/tokens](https://huggingface.co/settings/tokens) new token role=write <br />
|
405 |
+
""")
|
406 |
+
with gr.Group():
|
407 |
+
with gr.Box():
|
408 |
+
with gr.Row().style(equal_height=True):
|
409 |
+
text_pt_model_from = gr.Textbox(show_label=False, max_lines=1, placeholder="pt_model_from")
|
410 |
+
text_flax_model_to = gr.Textbox(show_label=False, max_lines=1, placeholder="flax_model_to")
|
411 |
+
text_flax_branch = gr.Textbox(show_label=False, value="flax", max_lines=1, placeholder="flax_branch")
|
412 |
+
text_flax_token = gr.Textbox(show_label=False, max_lines=1, placeholder="🤗 token")
|
413 |
+
out_flax = gr.Textbox(show_label=False)
|
414 |
+
with gr.Row().style(equal_height=True):
|
415 |
+
btn_clone_pt = gr.Button("Clone PT from 🤗")
|
416 |
+
btn_to_flax = gr.Button("Convert to Flax")
|
417 |
+
btn_push_flax = gr.Button("Push Flax to 🤗")
|
418 |
+
btn_delete_flax = gr.Button("Delete Flax")
|
419 |
+
btn_clone_pt.click(clone_pt, inputs=[text_pt_model_from], outputs=out_flax)
|
420 |
+
btn_to_flax.click(to_flax, outputs=out_flax)
|
421 |
+
btn_push_flax.click(push_flax, inputs=[text_flax_model_to, text_flax_token, text_flax_branch], outputs=out_flax)
|
422 |
+
btn_delete_flax.click(delete_flax, outputs=out_flax)
|
423 |
+
gr.Markdown(
|
424 |
+
"""
|
425 |
+
### pytorch to ckpt
|
426 |
+
pt_model_from = prompthero/openjourney <br />
|
427 |
+
ckpt_name = openjourney <br />
|
428 |
+
ckpt_model_to = camenduru/openjourney <br />
|
429 |
+
branch = ckpt <br />
|
430 |
+
token = get from [https://huggingface.co/settings/tokens](https://huggingface.co/settings/tokens) new token role=write
|
431 |
+
""")
|
432 |
+
with gr.Group():
|
433 |
+
with gr.Box():
|
434 |
+
with gr.Row().style(equal_height=True):
|
435 |
+
text_pt_model_from = gr.Textbox(show_label=False, max_lines=1, placeholder="pt_model_from")
|
436 |
+
text_ckpt_name = gr.Textbox(show_label=False, max_lines=1, placeholder="ckpt_name")
|
437 |
+
text_ckpt_model_to = gr.Textbox(show_label=False, max_lines=1, placeholder="ckpt_model_to")
|
438 |
+
text_ckpt_branch = gr.Textbox(show_label=False, value="ckpt", max_lines=1, placeholder="ckpt_branch")
|
439 |
+
text_ckpt_token = gr.Textbox(show_label=False, max_lines=1, placeholder="🤗 token")
|
440 |
+
out_ckpt = gr.Textbox(show_label=False)
|
441 |
+
with gr.Row().style(equal_height=True):
|
442 |
+
btn_clone_pt = gr.Button("Clone PT from 🤗")
|
443 |
+
btn_to_ckpt = gr.Button("Convert to CKPT")
|
444 |
+
btn_push_ckpt = gr.Button("Push CKPT to 🤗")
|
445 |
+
btn_delete_ckpt = gr.Button("Delete CKPT")
|
446 |
+
btn_clone_pt.click(clone_pt, inputs=[text_pt_model_from], outputs=out_ckpt)
|
447 |
+
btn_to_ckpt.click(to_ckpt, inputs=[text_ckpt_name], outputs=out_ckpt)
|
448 |
+
btn_push_ckpt.click(push_ckpt, inputs=[text_ckpt_model_to, text_ckpt_token, text_ckpt_branch], outputs=out_ckpt)
|
449 |
+
btn_delete_ckpt.click(delete_ckpt, outputs=out_ckpt)
|
450 |
+
gr.Markdown(
|
451 |
+
"""
|
452 |
+
### ckpt to safetensors <br />
|
453 |
+
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 />
|
454 |
+
safetensors_name = openjourney <br />
|
455 |
+
safetensors_model_to = camenduru/openjourney <br />
|
456 |
+
branch = safetensors <br />
|
457 |
+
token = get from [https://huggingface.co/settings/tokens](https://huggingface.co/settings/tokens) new token role=write <br />
|
458 |
+
""")
|
459 |
+
with gr.Group():
|
460 |
+
with gr.Box():
|
461 |
+
with gr.Row().style(equal_height=True):
|
462 |
+
text_ckpt_url_2 = gr.Textbox(show_label=False, max_lines=1, placeholder="ckpt_url_2")
|
463 |
+
text_ckpt_name_2 = gr.Textbox(show_label=False, max_lines=1, placeholder="ckpt_name_2")
|
464 |
+
text_safetensors_name_2 = gr.Textbox(show_label=False, max_lines=1, placeholder="safetensors_name_2")
|
465 |
+
text_safetensors_model_to = gr.Textbox(show_label=False, max_lines=1, placeholder="safetensors_model_to")
|
466 |
+
text_safetensors_branch = gr.Textbox(show_label=False, value="safetensors", max_lines=1, placeholder="safetensors_branch")
|
467 |
+
text_safetensors_token = gr.Textbox(show_label=False, max_lines=1, placeholder="🤗 token")
|
468 |
+
out_safetensors = gr.Textbox(show_label=False)
|
469 |
+
with gr.Row().style(equal_height=True):
|
470 |
+
btn_download_ckpt = gr.Button("Download CKPT")
|
471 |
+
btn_to_safetensors = gr.Button("Convert to Safetensors")
|
472 |
+
btn_push_safetensors = gr.Button("Push Safetensors to 🤗")
|
473 |
+
btn_delete_safetensors = gr.Button("Delete Safetensors")
|
474 |
+
btn_download_ckpt.click(download_ckpt, inputs=[text_ckpt_url_2, text_ckpt_name_2], outputs=out_safetensors)
|
475 |
+
btn_to_safetensors.click(to_safetensors, inputs=[text_ckpt_name_2, text_safetensors_name_2], outputs=out_safetensors)
|
476 |
+
btn_push_safetensors.click(push_safetensors, inputs=[text_safetensors_model_to, text_safetensors_token, text_safetensors_branch], outputs=out_safetensors)
|
477 |
+
btn_delete_safetensors.click(delete_safetensors, outputs=out_safetensors)
|
478 |
+
gr.Markdown(
|
479 |
+
"""
|
480 |
+
### safetensors to ckpt <br />
|
481 |
+
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 />
|
482 |
+
ckpt_name = openjourney <br />
|
483 |
+
ckpt_model_to = camenduru/openjourney <br />
|
484 |
+
branch = ckpt <br />
|
485 |
+
token = get from [https://huggingface.co/settings/tokens](https://huggingface.co/settings/tokens) new token role=write <br />
|
486 |
+
""")
|
487 |
+
with gr.Group():
|
488 |
+
with gr.Box():
|
489 |
+
with gr.Row().style(equal_height=True):
|
490 |
+
text_safetensors_url = gr.Textbox(show_label=False, max_lines=1, placeholder="safetensors_url")
|
491 |
+
text_safetensors_name = gr.Textbox(show_label=False, max_lines=1, placeholder="safetensors_name")
|
492 |
+
text_safetensors_to_ckpt_name = gr.Textbox(show_label=False, max_lines=1, placeholder="ckpt_name")
|
493 |
+
text_safetensors_to_ckpt_model_to = gr.Textbox(show_label=False, max_lines=1, placeholder="ckpt_model_to")
|
494 |
+
text_safetensors_to_ckpt_branch = gr.Textbox(show_label=False, value="ckpt", max_lines=1, placeholder="ckpt_branch")
|
495 |
+
text_safetensors_to_ckpt_token = gr.Textbox(show_label=False, max_lines=1, placeholder="🤗 token")
|
496 |
+
out_safetensors_to_ckpt = gr.Textbox(show_label=False)
|
497 |
+
with gr.Row().style(equal_height=True):
|
498 |
+
btn_download_safetensors = gr.Button("Download Safetensors")
|
499 |
+
btn_safetensors_to_ckpt = gr.Button("Convert to CKPT")
|
500 |
+
btn_push_safetensors_to_ckpt = gr.Button("Push CKPT to 🤗")
|
501 |
+
btn_delete_safetensors_ckpt = gr.Button("Delete CKPT")
|
502 |
+
btn_download_safetensors.click(download_safetensors, inputs=[text_safetensors_url, text_safetensors_name], outputs=out_safetensors_to_ckpt)
|
503 |
+
btn_safetensors_to_ckpt.click(from_safetensors_to_ckpt, inputs=[text_safetensors_name, text_safetensors_to_ckpt_name], outputs=out_safetensors_to_ckpt)
|
504 |
+
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)
|
505 |
+
btn_delete_safetensors_ckpt.click(delete_ckpt, outputs=out_safetensors_to_ckpt)
|
506 |
+
|
507 |
+
|
508 |
+
block.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|