Spaces:
Running
on
Zero
Running
on
Zero
Upload 2 files
Browse files- env.py +2 -2
- modutils.py +27 -24
env.py
CHANGED
@@ -41,8 +41,8 @@ load_diffusers_format_model = [
|
|
41 |
'KBlueLeaf/Kohaku-XL-Epsilon-rev2',
|
42 |
'KBlueLeaf/Kohaku-XL-Epsilon-rev3',
|
43 |
'KBlueLeaf/Kohaku-XL-Zeta',
|
44 |
-
'kayfahaarukku/UrangDiffusion-1.
|
45 |
-
'Eugeoter/artiwaifu-diffusion-
|
46 |
'Raelina/Rae-Diffusion-XL-V2',
|
47 |
'Raelina/Raemu-XL-V4',
|
48 |
]
|
|
|
41 |
'KBlueLeaf/Kohaku-XL-Epsilon-rev2',
|
42 |
'KBlueLeaf/Kohaku-XL-Epsilon-rev3',
|
43 |
'KBlueLeaf/Kohaku-XL-Zeta',
|
44 |
+
'kayfahaarukku/UrangDiffusion-1.3',
|
45 |
+
'Eugeoter/artiwaifu-diffusion-2.0',
|
46 |
'Raelina/Rae-Diffusion-XL-V2',
|
47 |
'Raelina/Raemu-XL-V4',
|
48 |
]
|
modutils.py
CHANGED
@@ -5,16 +5,10 @@ from huggingface_hub import HfApi
|
|
5 |
import os
|
6 |
from pathlib import Path
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
HF_MODEL_USER_LIKES,
|
13 |
-
directory_loras,
|
14 |
-
hf_read_token,
|
15 |
-
hf_token,
|
16 |
-
CIVITAI_API_KEY,
|
17 |
-
)
|
18 |
|
19 |
|
20 |
def get_user_agent():
|
@@ -113,8 +107,8 @@ def save_gallery_images(images, progress=gr.Progress(track_tqdm=True)):
|
|
113 |
try:
|
114 |
if oldpath.exists():
|
115 |
newpath = oldpath.resolve().rename(Path(filename).resolve())
|
116 |
-
except Exception:
|
117 |
-
|
118 |
finally:
|
119 |
output_paths.append(str(newpath))
|
120 |
output_images.append((str(newpath), str(filename)))
|
@@ -128,7 +122,8 @@ def download_private_repo(repo_id, dir_path, is_replace):
|
|
128 |
try:
|
129 |
snapshot_download(repo_id=repo_id, local_dir=dir_path, allow_patterns=['*.ckpt', '*.pt', '*.pth', '*.safetensors', '*.bin'], use_auth_token=hf_read_token)
|
130 |
except Exception as e:
|
131 |
-
print(f"Error: Failed to download {repo_id}.
|
|
|
132 |
return
|
133 |
if is_replace:
|
134 |
for file in Path(dir_path).glob("*"):
|
@@ -147,7 +142,8 @@ def get_private_model_list(repo_id, dir_path):
|
|
147 |
try:
|
148 |
files = api.list_repo_files(repo_id, token=hf_read_token)
|
149 |
except Exception as e:
|
150 |
-
print(f"Error: Failed to list {repo_id}.
|
|
|
151 |
return []
|
152 |
model_list = []
|
153 |
for file in files:
|
@@ -169,7 +165,8 @@ def download_private_file(repo_id, path, is_replace):
|
|
169 |
try:
|
170 |
hf_hub_download(repo_id=repo_id, filename=filename, local_dir=dirname, use_auth_token=hf_read_token)
|
171 |
except Exception as e:
|
172 |
-
print(f"Error: Failed to download {filename}.
|
|
|
173 |
return
|
174 |
if is_replace:
|
175 |
file.resolve().rename(newpath.resolve())
|
@@ -195,7 +192,8 @@ def get_model_id_list():
|
|
195 |
for author in HF_MODEL_USER_EX:
|
196 |
models_ex = api.list_models(author=author, cardData=True, sort="last_modified")
|
197 |
except Exception as e:
|
198 |
-
print(f"Error: Failed to list {author}'s models.
|
|
|
199 |
return model_ids
|
200 |
for model in models_likes:
|
201 |
model_ids.append(model.id) if not model.private else ""
|
@@ -219,17 +217,17 @@ def get_t2i_model_info(repo_id: str):
|
|
219 |
if " " in repo_id or not api.repo_exists(repo_id): return ""
|
220 |
model = api.model_info(repo_id=repo_id)
|
221 |
except Exception as e:
|
222 |
-
print(f"Error: Failed to get {repo_id}'s info.
|
|
|
223 |
return ""
|
224 |
if model.private or model.gated: return ""
|
225 |
tags = model.tags
|
226 |
info = []
|
227 |
url = f"https://huggingface.co/{repo_id}/"
|
228 |
if not 'diffusers' in tags: return ""
|
229 |
-
if 'diffusers:
|
230 |
-
|
231 |
-
elif 'diffusers:StableDiffusionPipeline' in tags:
|
232 |
-
info.append("SD1.5")
|
233 |
if model.card_data and model.card_data.tags:
|
234 |
info.extend(list_sub(model.card_data.tags, ['text-to-image', 'stable-diffusion', 'stable-diffusion-api', 'safetensors', 'stable-diffusion-xl']))
|
235 |
info.append(f"DLs: {model.downloads}")
|
@@ -248,6 +246,7 @@ def get_tupled_model_list(model_list):
|
|
248 |
if not api.repo_exists(repo_id): continue
|
249 |
model = api.model_info(repo_id=repo_id)
|
250 |
except Exception as e:
|
|
|
251 |
continue
|
252 |
if model.private or model.gated: continue
|
253 |
tags = model.tags
|
@@ -274,8 +273,8 @@ try:
|
|
274 |
d = json.load(f)
|
275 |
for k, v in d.items():
|
276 |
private_lora_dict[escape_lora_basename(k)] = v
|
277 |
-
except Exception:
|
278 |
-
|
279 |
loras_dict = {"None": ["", "", "", "", ""], "": ["", "", "", "", ""]} | private_lora_dict.copy()
|
280 |
civitai_not_exists_list = []
|
281 |
loras_url_to_path_dict = {} # {"URL to download": "local filepath", ...}
|
@@ -323,6 +322,7 @@ def get_civitai_info(path):
|
|
323 |
try:
|
324 |
r = session.get(url, params=params, headers=headers, stream=True, timeout=(3.0, 15))
|
325 |
except Exception as e:
|
|
|
326 |
return ["", "", "", "", ""]
|
327 |
if not r.ok: return None
|
328 |
json = r.json()
|
@@ -421,7 +421,8 @@ def copy_lora(path: str, new_path: str):
|
|
421 |
if cpath.exists():
|
422 |
try:
|
423 |
shutil.copy(str(cpath.resolve()), str(npath.resolve()))
|
424 |
-
except Exception:
|
|
|
425 |
return None
|
426 |
update_lora_dict(str(npath))
|
427 |
return new_path
|
@@ -1216,6 +1217,8 @@ def get_model_pipeline(repo_id: str):
|
|
1216 |
if model.private or model.gated: return default
|
1217 |
tags = model.tags
|
1218 |
if not 'diffusers' in tags: return default
|
|
|
|
|
1219 |
if 'diffusers:StableDiffusionXLPipeline' in tags:
|
1220 |
return "StableDiffusionXLPipeline"
|
1221 |
elif 'diffusers:StableDiffusionPipeline' in tags:
|
|
|
5 |
import os
|
6 |
from pathlib import Path
|
7 |
|
8 |
+
|
9 |
+
from env import (HF_LORA_PRIVATE_REPOS1, HF_LORA_PRIVATE_REPOS2,
|
10 |
+
HF_MODEL_USER_EX, HF_MODEL_USER_LIKES,
|
11 |
+
directory_loras, hf_read_token, hf_token, CIVITAI_API_KEY)
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
|
14 |
def get_user_agent():
|
|
|
107 |
try:
|
108 |
if oldpath.exists():
|
109 |
newpath = oldpath.resolve().rename(Path(filename).resolve())
|
110 |
+
except Exception as e:
|
111 |
+
print(e)
|
112 |
finally:
|
113 |
output_paths.append(str(newpath))
|
114 |
output_images.append((str(newpath), str(filename)))
|
|
|
122 |
try:
|
123 |
snapshot_download(repo_id=repo_id, local_dir=dir_path, allow_patterns=['*.ckpt', '*.pt', '*.pth', '*.safetensors', '*.bin'], use_auth_token=hf_read_token)
|
124 |
except Exception as e:
|
125 |
+
print(f"Error: Failed to download {repo_id}.")
|
126 |
+
print(e)
|
127 |
return
|
128 |
if is_replace:
|
129 |
for file in Path(dir_path).glob("*"):
|
|
|
142 |
try:
|
143 |
files = api.list_repo_files(repo_id, token=hf_read_token)
|
144 |
except Exception as e:
|
145 |
+
print(f"Error: Failed to list {repo_id}.")
|
146 |
+
print(e)
|
147 |
return []
|
148 |
model_list = []
|
149 |
for file in files:
|
|
|
165 |
try:
|
166 |
hf_hub_download(repo_id=repo_id, filename=filename, local_dir=dirname, use_auth_token=hf_read_token)
|
167 |
except Exception as e:
|
168 |
+
print(f"Error: Failed to download {filename}.")
|
169 |
+
print(e)
|
170 |
return
|
171 |
if is_replace:
|
172 |
file.resolve().rename(newpath.resolve())
|
|
|
192 |
for author in HF_MODEL_USER_EX:
|
193 |
models_ex = api.list_models(author=author, cardData=True, sort="last_modified")
|
194 |
except Exception as e:
|
195 |
+
print(f"Error: Failed to list {author}'s models.")
|
196 |
+
print(e)
|
197 |
return model_ids
|
198 |
for model in models_likes:
|
199 |
model_ids.append(model.id) if not model.private else ""
|
|
|
217 |
if " " in repo_id or not api.repo_exists(repo_id): return ""
|
218 |
model = api.model_info(repo_id=repo_id)
|
219 |
except Exception as e:
|
220 |
+
print(f"Error: Failed to get {repo_id}'s info.")
|
221 |
+
print(e)
|
222 |
return ""
|
223 |
if model.private or model.gated: return ""
|
224 |
tags = model.tags
|
225 |
info = []
|
226 |
url = f"https://huggingface.co/{repo_id}/"
|
227 |
if not 'diffusers' in tags: return ""
|
228 |
+
if 'diffusers:FluxPipeline' in tags: info.append("FLUX.1")
|
229 |
+
elif 'diffusers:StableDiffusionXLPipeline' in tags: info.append("SDXL")
|
230 |
+
elif 'diffusers:StableDiffusionPipeline' in tags: info.append("SD1.5")
|
|
|
231 |
if model.card_data and model.card_data.tags:
|
232 |
info.extend(list_sub(model.card_data.tags, ['text-to-image', 'stable-diffusion', 'stable-diffusion-api', 'safetensors', 'stable-diffusion-xl']))
|
233 |
info.append(f"DLs: {model.downloads}")
|
|
|
246 |
if not api.repo_exists(repo_id): continue
|
247 |
model = api.model_info(repo_id=repo_id)
|
248 |
except Exception as e:
|
249 |
+
print(e)
|
250 |
continue
|
251 |
if model.private or model.gated: continue
|
252 |
tags = model.tags
|
|
|
273 |
d = json.load(f)
|
274 |
for k, v in d.items():
|
275 |
private_lora_dict[escape_lora_basename(k)] = v
|
276 |
+
except Exception as e:
|
277 |
+
print(e)
|
278 |
loras_dict = {"None": ["", "", "", "", ""], "": ["", "", "", "", ""]} | private_lora_dict.copy()
|
279 |
civitai_not_exists_list = []
|
280 |
loras_url_to_path_dict = {} # {"URL to download": "local filepath", ...}
|
|
|
322 |
try:
|
323 |
r = session.get(url, params=params, headers=headers, stream=True, timeout=(3.0, 15))
|
324 |
except Exception as e:
|
325 |
+
print(e)
|
326 |
return ["", "", "", "", ""]
|
327 |
if not r.ok: return None
|
328 |
json = r.json()
|
|
|
421 |
if cpath.exists():
|
422 |
try:
|
423 |
shutil.copy(str(cpath.resolve()), str(npath.resolve()))
|
424 |
+
except Exception as e:
|
425 |
+
print(e)
|
426 |
return None
|
427 |
update_lora_dict(str(npath))
|
428 |
return new_path
|
|
|
1217 |
if model.private or model.gated: return default
|
1218 |
tags = model.tags
|
1219 |
if not 'diffusers' in tags: return default
|
1220 |
+
if 'diffusers:FluxPipeline' in tags:
|
1221 |
+
return "FluxPipeline"
|
1222 |
if 'diffusers:StableDiffusionXLPipeline' in tags:
|
1223 |
return "StableDiffusionXLPipeline"
|
1224 |
elif 'diffusers:StableDiffusionPipeline' in tags:
|