Spaces:
Running
on
Zero
Running
on
Zero
Upload 4 files
Browse files
README.md
CHANGED
|
@@ -4,7 +4,7 @@ emoji: 🧩🖼️📦
|
|
| 4 |
colorFrom: red
|
| 5 |
colorTo: pink
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version: 4.
|
| 8 |
app_file: app.py
|
| 9 |
pinned: true
|
| 10 |
header: mini
|
|
|
|
| 4 |
colorFrom: red
|
| 5 |
colorTo: pink
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 4.38.1
|
| 8 |
app_file: app.py
|
| 9 |
pinned: true
|
| 10 |
header: mini
|
app.py
CHANGED
|
@@ -160,14 +160,6 @@ def process_string(input_string):
|
|
| 160 |
return None
|
| 161 |
|
| 162 |
|
| 163 |
-
directory_models = 'models'
|
| 164 |
-
os.makedirs(directory_models, exist_ok=True)
|
| 165 |
-
directory_loras = 'loras'
|
| 166 |
-
os.makedirs(directory_loras, exist_ok=True)
|
| 167 |
-
directory_vaes = 'vaes'
|
| 168 |
-
os.makedirs(directory_vaes, exist_ok=True)
|
| 169 |
-
|
| 170 |
-
|
| 171 |
## BEGIN MOD
|
| 172 |
from modutils import (
|
| 173 |
download_private_repo,
|
|
@@ -179,70 +171,41 @@ from modutils import (
|
|
| 179 |
list_sub,
|
| 180 |
get_tupled_embed_list,
|
| 181 |
update_lora_dict,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
HF_LORA_ESSENTIAL_PRIVATE_REPO,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
)
|
| 184 |
|
| 185 |
-
# - **Download
|
| 186 |
-
|
| 187 |
-
download_model = ""
|
| 188 |
# - **Download VAEs**
|
| 189 |
-
download_vae_list = [
|
| 190 |
-
'https://huggingface.co/madebyollin/sdxl-vae-fp16-fix/resolve/main/sdxl.vae.safetensors?download=true',
|
| 191 |
-
'https://huggingface.co/nubby/blessed-sdxl-vae-fp16-fix/resolve/main/sdxl_vae-fp16fix-c-1.1-b-0.5.safetensors?download=true',
|
| 192 |
-
'https://huggingface.co/nubby/blessed-sdxl-vae-fp16-fix/resolve/main/sdxl_vae-fp16fix-blessed.safetensors?download=true',
|
| 193 |
-
]
|
| 194 |
download_vae = ", ".join(download_vae_list)
|
| 195 |
# - **Download LoRAs**
|
| 196 |
-
download_lora_list = []
|
| 197 |
download_lora = ", ".join(download_lora_list)
|
| 198 |
|
| 199 |
download_private_repo(HF_LORA_ESSENTIAL_PRIVATE_REPO, directory_loras, True)
|
| 200 |
-
download_private_repo(
|
| 201 |
-
|
| 202 |
-
load_diffusers_format_model = [
|
| 203 |
-
'stabilityai/stable-diffusion-xl-base-1.0',
|
| 204 |
-
'cagliostrolab/animagine-xl-3.1',
|
| 205 |
-
'misri/epicrealismXL_v7FinalDestination',
|
| 206 |
-
'misri/juggernautXL_juggernautX',
|
| 207 |
-
'misri/zavychromaxl_v80',
|
| 208 |
-
'SG161222/RealVisXL_V4.0',
|
| 209 |
-
'misri/newrealityxlAllInOne_Newreality40',
|
| 210 |
-
'eienmojiki/Anything-XL',
|
| 211 |
-
'eienmojiki/Starry-XL-v5.2',
|
| 212 |
-
'gsdf/CounterfeitXL',
|
| 213 |
-
'kitty7779/ponyDiffusionV6XL',
|
| 214 |
-
'John6666/ebara-mfcg-pony-mix-v12-sdxl',
|
| 215 |
-
'John6666/t-ponynai3-v51-sdxl',
|
| 216 |
-
'yodayo-ai/kivotos-xl-2.0',
|
| 217 |
-
'yodayo-ai/holodayo-xl-2.1',
|
| 218 |
-
'digiplay/majicMIX_sombre_v2',
|
| 219 |
-
'digiplay/majicMIX_realistic_v6',
|
| 220 |
-
'digiplay/majicMIX_realistic_v7',
|
| 221 |
-
'digiplay/DreamShaper_8',
|
| 222 |
-
'digiplay/BeautifulArt_v1',
|
| 223 |
-
'digiplay/DarkSushi2.5D_v1',
|
| 224 |
-
'digiplay/darkphoenix3D_v1.1',
|
| 225 |
-
'digiplay/BeenYouLiteL11_diffusers',
|
| 226 |
-
'rubbrband/revAnimated_v2Rebirth',
|
| 227 |
-
'youknownothing/cyberrealistic_v50',
|
| 228 |
-
'votepurchase/counterfeitV30_v30',
|
| 229 |
-
'Meina/MeinaMix_V11',
|
| 230 |
-
'Meina/MeinaUnreal_V5',
|
| 231 |
-
'Meina/MeinaPastel_V7',
|
| 232 |
-
'rubbrband/realcartoon3d_v16',
|
| 233 |
-
'rubbrband/realcartoonRealistic_v14',
|
| 234 |
-
'KBlueLeaf/Kohaku-XL-Epsilon-rev2',
|
| 235 |
-
'KBlueLeaf/Kohaku-XL-Epsilon-rev3',
|
| 236 |
-
'Raelina/Rae-Diffusion-XL-V2',
|
| 237 |
-
'Raelina/Raemu-XL-V4',
|
| 238 |
-
]
|
| 239 |
|
| 240 |
load_diffusers_format_model = list_uniq(get_model_id_list() + load_diffusers_format_model)
|
| 241 |
## END MOD
|
| 242 |
|
| 243 |
-
CIVITAI_API_KEY = os.environ.get("CIVITAI_API_KEY")
|
| 244 |
-
hf_token = os.environ.get("HF_TOKEN")
|
| 245 |
-
|
| 246 |
# Download stuffs
|
| 247 |
for url in [url.strip() for url in download_model.split(',')]:
|
| 248 |
if not os.path.exists(f"./models/{url.split('/')[-1]}"):
|
|
@@ -255,14 +218,6 @@ for url in [url.strip() for url in download_lora.split(',')]:
|
|
| 255 |
download_things(directory_loras, url, hf_token, CIVITAI_API_KEY)
|
| 256 |
|
| 257 |
# Download Embeddings
|
| 258 |
-
directory_embeds = 'embedings'
|
| 259 |
-
os.makedirs(directory_embeds, exist_ok=True)
|
| 260 |
-
download_embeds = [
|
| 261 |
-
'https://huggingface.co/datasets/Nerfgun3/bad_prompt/blob/main/bad_prompt_version2.pt',
|
| 262 |
-
'https://huggingface.co/embed/negative/resolve/main/EasyNegativeV2.safetensors',
|
| 263 |
-
'https://huggingface.co/embed/negative/resolve/main/bad-hands-5.pt',
|
| 264 |
-
]
|
| 265 |
-
|
| 266 |
for url_embed in download_embeds:
|
| 267 |
if not os.path.exists(f"./embedings/{url_embed.split('/')[-1]}"):
|
| 268 |
download_things(directory_embeds, url_embed, hf_token, CIVITAI_API_KEY)
|
|
@@ -272,19 +227,13 @@ embed_list = get_model_list(directory_embeds)
|
|
| 272 |
model_list = get_model_list(directory_models)
|
| 273 |
model_list = load_diffusers_format_model + model_list
|
| 274 |
## BEGIN MOD
|
| 275 |
-
lora_model_list =
|
| 276 |
-
lora_model_list.insert(0, "None")
|
| 277 |
-
lora_model_list.insert(0, "")
|
| 278 |
vae_model_list = get_model_list(directory_vaes)
|
| 279 |
vae_model_list.insert(0, "None")
|
| 280 |
|
| 281 |
-
directory_embeds_sdxl
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
directory_embeds_postitive_sdxl = 'embedings_xl/positive'
|
| 285 |
-
os.makedirs(directory_embeds_postitive_sdxl, exist_ok=True)
|
| 286 |
-
download_private_repo('John6666/embeddingspositivetest', directory_embeds_postitive_sdxl, False)
|
| 287 |
-
embed_sdxl_list = get_model_list(directory_embeds_sdxl) + get_model_list(directory_embeds_postitive_sdxl)
|
| 288 |
|
| 289 |
def get_embed_list(pipeline_name):
|
| 290 |
return get_tupled_embed_list(embed_sdxl_list if pipeline_name == "StableDiffusionXLPipeline" else embed_list)
|
|
@@ -303,9 +252,7 @@ def get_my_lora(link_url):
|
|
| 303 |
new_path = Path(f'{path.parent.name}/{escape_lora_basename(path.stem)}{path.suffix}')
|
| 304 |
path.resolve().rename(new_path.resolve())
|
| 305 |
update_lora_dict(str(new_path))
|
| 306 |
-
new_lora_model_list =
|
| 307 |
-
new_lora_model_list.insert(0, "None")
|
| 308 |
-
new_lora_model_list.insert(0, "")
|
| 309 |
|
| 310 |
return gr.update(
|
| 311 |
choices=get_lora_tupled_list(new_lora_model_list), value=new_lora_model_list[-1]
|
|
@@ -638,6 +585,8 @@ class GuiSD:
|
|
| 638 |
|
| 639 |
## BEGIN MOD
|
| 640 |
prompt, neg_prompt = insert_model_recom_prompt(prompt, neg_prompt, model_name)
|
|
|
|
|
|
|
| 641 |
## END MOD
|
| 642 |
|
| 643 |
if model_name in model_list:
|
|
@@ -1671,6 +1620,7 @@ with gr.Blocks(theme="NoCrypt/miku@>=1.2.2", elem_id="main", css=CSS) as app:
|
|
| 1671 |
fn=search_civitai_lora,
|
| 1672 |
inputs=[search_civitai_query_lora, search_civitai_basemodel_lora],
|
| 1673 |
outputs=[search_civitai_result_lora, search_civitai_desc_lora, search_civitai_button_lora, search_civitai_query_lora],
|
|
|
|
| 1674 |
scroll_to_output=True,
|
| 1675 |
)
|
| 1676 |
search_civitai_result_lora.change(select_civitai_lora, [search_civitai_result_lora], [text_lora, search_civitai_desc_lora], queue=False, scroll_to_output=True)
|
|
|
|
| 160 |
return None
|
| 161 |
|
| 162 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
## BEGIN MOD
|
| 164 |
from modutils import (
|
| 165 |
download_private_repo,
|
|
|
|
| 171 |
list_sub,
|
| 172 |
get_tupled_embed_list,
|
| 173 |
update_lora_dict,
|
| 174 |
+
get_lora_model_list,
|
| 175 |
+
)
|
| 176 |
+
from env import (
|
| 177 |
+
hf_token,
|
| 178 |
+
CIVITAI_API_KEY,
|
| 179 |
HF_LORA_ESSENTIAL_PRIVATE_REPO,
|
| 180 |
+
HF_VAE_PRIVATE_REPO,
|
| 181 |
+
HF_SDXL_EMBEDS_NEGATIVE_PRIVATE_REPO,
|
| 182 |
+
HF_SDXL_EMBEDS_POSITIVE_PRIVATE_REPO,
|
| 183 |
+
directory_models,
|
| 184 |
+
directory_loras,
|
| 185 |
+
directory_vaes,
|
| 186 |
+
directory_embeds,
|
| 187 |
+
directory_embeds_sdxl,
|
| 188 |
+
directory_embeds_positive_sdxl,
|
| 189 |
+
load_diffusers_format_model,
|
| 190 |
+
download_model_list,
|
| 191 |
+
download_lora_list,
|
| 192 |
+
download_vae_list,
|
| 193 |
+
download_embeds,
|
| 194 |
)
|
| 195 |
|
| 196 |
+
# - **Download Models**
|
| 197 |
+
download_model = ", ".join(download_model_list)
|
|
|
|
| 198 |
# - **Download VAEs**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
download_vae = ", ".join(download_vae_list)
|
| 200 |
# - **Download LoRAs**
|
|
|
|
| 201 |
download_lora = ", ".join(download_lora_list)
|
| 202 |
|
| 203 |
download_private_repo(HF_LORA_ESSENTIAL_PRIVATE_REPO, directory_loras, True)
|
| 204 |
+
download_private_repo(HF_VAE_PRIVATE_REPO, directory_vaes, False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 205 |
|
| 206 |
load_diffusers_format_model = list_uniq(get_model_id_list() + load_diffusers_format_model)
|
| 207 |
## END MOD
|
| 208 |
|
|
|
|
|
|
|
|
|
|
| 209 |
# Download stuffs
|
| 210 |
for url in [url.strip() for url in download_model.split(',')]:
|
| 211 |
if not os.path.exists(f"./models/{url.split('/')[-1]}"):
|
|
|
|
| 218 |
download_things(directory_loras, url, hf_token, CIVITAI_API_KEY)
|
| 219 |
|
| 220 |
# Download Embeddings
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 221 |
for url_embed in download_embeds:
|
| 222 |
if not os.path.exists(f"./embedings/{url_embed.split('/')[-1]}"):
|
| 223 |
download_things(directory_embeds, url_embed, hf_token, CIVITAI_API_KEY)
|
|
|
|
| 227 |
model_list = get_model_list(directory_models)
|
| 228 |
model_list = load_diffusers_format_model + model_list
|
| 229 |
## BEGIN MOD
|
| 230 |
+
lora_model_list = get_lora_model_list()
|
|
|
|
|
|
|
| 231 |
vae_model_list = get_model_list(directory_vaes)
|
| 232 |
vae_model_list.insert(0, "None")
|
| 233 |
|
| 234 |
+
download_private_repo(HF_SDXL_EMBEDS_NEGATIVE_PRIVATE_REPO, directory_embeds_sdxl, False)
|
| 235 |
+
download_private_repo(HF_SDXL_EMBEDS_POSITIVE_PRIVATE_REPO, directory_embeds_positive_sdxl, False)
|
| 236 |
+
embed_sdxl_list = get_model_list(directory_embeds_sdxl) + get_model_list(directory_embeds_positive_sdxl)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
|
| 238 |
def get_embed_list(pipeline_name):
|
| 239 |
return get_tupled_embed_list(embed_sdxl_list if pipeline_name == "StableDiffusionXLPipeline" else embed_list)
|
|
|
|
| 252 |
new_path = Path(f'{path.parent.name}/{escape_lora_basename(path.stem)}{path.suffix}')
|
| 253 |
path.resolve().rename(new_path.resolve())
|
| 254 |
update_lora_dict(str(new_path))
|
| 255 |
+
new_lora_model_list = get_lora_model_list()
|
|
|
|
|
|
|
| 256 |
|
| 257 |
return gr.update(
|
| 258 |
choices=get_lora_tupled_list(new_lora_model_list), value=new_lora_model_list[-1]
|
|
|
|
| 585 |
|
| 586 |
## BEGIN MOD
|
| 587 |
prompt, neg_prompt = insert_model_recom_prompt(prompt, neg_prompt, model_name)
|
| 588 |
+
global lora_model_list
|
| 589 |
+
lora_model_list = get_lora_model_list()
|
| 590 |
## END MOD
|
| 591 |
|
| 592 |
if model_name in model_list:
|
|
|
|
| 1620 |
fn=search_civitai_lora,
|
| 1621 |
inputs=[search_civitai_query_lora, search_civitai_basemodel_lora],
|
| 1622 |
outputs=[search_civitai_result_lora, search_civitai_desc_lora, search_civitai_button_lora, search_civitai_query_lora],
|
| 1623 |
+
queue=True,
|
| 1624 |
scroll_to_output=True,
|
| 1625 |
)
|
| 1626 |
search_civitai_result_lora.change(select_civitai_lora, [search_civitai_result_lora], [text_lora, search_civitai_desc_lora], queue=False, scroll_to_output=True)
|
env.py
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
CIVITAI_API_KEY = os.environ.get("CIVITAI_API_KEY")
|
| 4 |
+
hf_token = os.environ.get("HF_TOKEN")
|
| 5 |
+
hf_read_token = os.environ.get('HF_READ_TOKEN') # only use for private repo
|
| 6 |
+
|
| 7 |
+
# - **List Models**
|
| 8 |
+
load_diffusers_format_model = [
|
| 9 |
+
'stabilityai/stable-diffusion-xl-base-1.0',
|
| 10 |
+
'cagliostrolab/animagine-xl-3.1',
|
| 11 |
+
'misri/epicrealismXL_v7FinalDestination',
|
| 12 |
+
'misri/juggernautXL_juggernautX',
|
| 13 |
+
'misri/zavychromaxl_v80',
|
| 14 |
+
'SG161222/RealVisXL_V4.0',
|
| 15 |
+
'misri/newrealityxlAllInOne_Newreality40',
|
| 16 |
+
'eienmojiki/Anything-XL',
|
| 17 |
+
'eienmojiki/Starry-XL-v5.2',
|
| 18 |
+
'gsdf/CounterfeitXL',
|
| 19 |
+
'kitty7779/ponyDiffusionV6XL',
|
| 20 |
+
'John6666/ebara-mfcg-pony-mix-v12-sdxl',
|
| 21 |
+
'John6666/t-ponynai3-v51-sdxl',
|
| 22 |
+
'yodayo-ai/kivotos-xl-2.0',
|
| 23 |
+
'yodayo-ai/holodayo-xl-2.1',
|
| 24 |
+
'digiplay/majicMIX_sombre_v2',
|
| 25 |
+
'digiplay/majicMIX_realistic_v6',
|
| 26 |
+
'digiplay/majicMIX_realistic_v7',
|
| 27 |
+
'digiplay/DreamShaper_8',
|
| 28 |
+
'digiplay/BeautifulArt_v1',
|
| 29 |
+
'digiplay/DarkSushi2.5D_v1',
|
| 30 |
+
'digiplay/darkphoenix3D_v1.1',
|
| 31 |
+
'digiplay/BeenYouLiteL11_diffusers',
|
| 32 |
+
'rubbrband/revAnimated_v2Rebirth',
|
| 33 |
+
'youknownothing/cyberrealistic_v50',
|
| 34 |
+
'votepurchase/counterfeitV30_v30',
|
| 35 |
+
'Meina/MeinaMix_V11',
|
| 36 |
+
'Meina/MeinaUnreal_V5',
|
| 37 |
+
'Meina/MeinaPastel_V7',
|
| 38 |
+
'rubbrband/realcartoon3d_v16',
|
| 39 |
+
'rubbrband/realcartoonRealistic_v14',
|
| 40 |
+
'KBlueLeaf/Kohaku-XL-Epsilon-rev2',
|
| 41 |
+
'KBlueLeaf/Kohaku-XL-Epsilon-rev3',
|
| 42 |
+
'Raelina/Rae-Diffusion-XL-V2',
|
| 43 |
+
'Raelina/Raemu-XL-V4',
|
| 44 |
+
]
|
| 45 |
+
|
| 46 |
+
# List all Models for specified user
|
| 47 |
+
HF_MODEL_USER_LIKES = ["votepurchase"] # sorted by number of likes
|
| 48 |
+
HF_MODEL_USER_EX = ["John6666"] # sorted by a special rule
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
# - **Download Models**
|
| 52 |
+
download_model_list = [
|
| 53 |
+
]
|
| 54 |
+
|
| 55 |
+
# - **Download VAEs**
|
| 56 |
+
download_vae_list = [
|
| 57 |
+
'https://huggingface.co/madebyollin/sdxl-vae-fp16-fix/resolve/main/sdxl.vae.safetensors?download=true',
|
| 58 |
+
'https://huggingface.co/nubby/blessed-sdxl-vae-fp16-fix/resolve/main/sdxl_vae-fp16fix-c-1.1-b-0.5.safetensors?download=true',
|
| 59 |
+
'https://huggingface.co/nubby/blessed-sdxl-vae-fp16-fix/resolve/main/sdxl_vae-fp16fix-blessed.safetensors?download=true',
|
| 60 |
+
]
|
| 61 |
+
|
| 62 |
+
# - **Download LoRAs**
|
| 63 |
+
download_lora_list = [
|
| 64 |
+
]
|
| 65 |
+
|
| 66 |
+
# Download Embeddings
|
| 67 |
+
download_embeds = [
|
| 68 |
+
'https://huggingface.co/datasets/Nerfgun3/bad_prompt/blob/main/bad_prompt_version2.pt',
|
| 69 |
+
'https://huggingface.co/embed/negative/resolve/main/EasyNegativeV2.safetensors',
|
| 70 |
+
'https://huggingface.co/embed/negative/resolve/main/bad-hands-5.pt',
|
| 71 |
+
]
|
| 72 |
+
|
| 73 |
+
directory_models = 'models'
|
| 74 |
+
os.makedirs(directory_models, exist_ok=True)
|
| 75 |
+
directory_loras = 'loras'
|
| 76 |
+
os.makedirs(directory_loras, exist_ok=True)
|
| 77 |
+
directory_vaes = 'vaes'
|
| 78 |
+
os.makedirs(directory_vaes, exist_ok=True)
|
| 79 |
+
directory_embeds = 'embedings'
|
| 80 |
+
os.makedirs(directory_embeds, exist_ok=True)
|
| 81 |
+
|
| 82 |
+
directory_embeds_sdxl = 'embedings_xl'
|
| 83 |
+
os.makedirs(directory_embeds_sdxl, exist_ok=True)
|
| 84 |
+
directory_embeds_positive_sdxl = 'embedings_xl/positive'
|
| 85 |
+
os.makedirs(directory_embeds_positive_sdxl, exist_ok=True)
|
| 86 |
+
|
| 87 |
+
HF_LORA_PRIVATE_REPOS1 = ['John6666/loratest1', 'John6666/loratest3', 'John6666/loratest4', 'John6666/loratest6']
|
| 88 |
+
HF_LORA_PRIVATE_REPOS2 = ['John6666/loratest10', 'John6666/loratest'] # to be sorted as 1 repo
|
| 89 |
+
HF_LORA_PRIVATE_REPOS = HF_LORA_PRIVATE_REPOS1 + HF_LORA_PRIVATE_REPOS2
|
| 90 |
+
HF_LORA_ESSENTIAL_PRIVATE_REPO = 'John6666/loratest1' # to be downloaded on run app
|
| 91 |
+
HF_VAE_PRIVATE_REPO = 'John6666/vaetest'
|
| 92 |
+
HF_SDXL_EMBEDS_NEGATIVE_PRIVATE_REPO = 'John6666/embeddingstest'
|
| 93 |
+
HF_SDXL_EMBEDS_POSITIVE_PRIVATE_REPO = 'John6666/embeddingspositivetest'
|
modutils.py
CHANGED
|
@@ -1,18 +1,16 @@
|
|
| 1 |
-
import os
|
| 2 |
import json
|
| 3 |
import gradio as gr
|
| 4 |
-
from PIL import Image
|
| 5 |
from huggingface_hub import HfApi
|
| 6 |
-
from requests import HTTPError, Timeout
|
| 7 |
from pathlib import Path
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
hf_read_token
|
|
|
|
| 16 |
|
| 17 |
def get_user_agent():
|
| 18 |
return 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:127.0) Gecko/20100101 Firefox/127.0'
|
|
@@ -103,7 +101,10 @@ def get_private_model_list(repo_id, dir_path):
|
|
| 103 |
return model_list
|
| 104 |
|
| 105 |
|
|
|
|
| 106 |
def get_private_lora_model_lists():
|
|
|
|
|
|
|
| 107 |
models1 = []
|
| 108 |
models2 = []
|
| 109 |
for repo in HF_LORA_PRIVATE_REPOS1:
|
|
@@ -111,6 +112,7 @@ def get_private_lora_model_lists():
|
|
| 111 |
for repo in HF_LORA_PRIVATE_REPOS2:
|
| 112 |
models2.extend(get_private_model_list(repo, directory_loras))
|
| 113 |
models = list_uniq(models1 + sorted(models2))
|
|
|
|
| 114 |
return models
|
| 115 |
|
| 116 |
|
|
@@ -139,15 +141,19 @@ def get_model_id_list():
|
|
| 139 |
api = HfApi()
|
| 140 |
model_ids = []
|
| 141 |
try:
|
| 142 |
-
|
| 143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
except Exception as e:
|
| 145 |
return model_ids
|
| 146 |
-
for model in
|
| 147 |
model_ids.append(model.id) if not model.private else ""
|
| 148 |
anime_models = []
|
| 149 |
real_models = []
|
| 150 |
-
for model in
|
| 151 |
if not model.private:
|
| 152 |
anime_models.append(model.id) if 'anime' in model.tags else real_models.append(model.id)
|
| 153 |
model_ids.extend(anime_models)
|
|
@@ -220,13 +226,15 @@ def save_gallery_images(images, progress=gr.Progress(track_tqdm=True)):
|
|
| 220 |
output_paths = []
|
| 221 |
for image in images:
|
| 222 |
filename = basename + str(i) + ".png"
|
| 223 |
-
|
| 224 |
-
|
|
|
|
|
|
|
|
|
|
| 225 |
output_paths.append(str(newpath))
|
| 226 |
output_images.append((str(newpath), str(filename)))
|
| 227 |
-
i += 1
|
| 228 |
progress(1, desc="Gallery updated.")
|
| 229 |
-
return gr.update(value=output_images), gr.update(value=output_paths), gr.update(visible=True)
|
| 230 |
|
| 231 |
|
| 232 |
optimization_list = {
|
|
@@ -302,10 +310,13 @@ def set_lora_prompt(prompt_gui, prompt_syntax_gui, lora1_gui, lora_scale_1_gui,
|
|
| 302 |
|
| 303 |
|
| 304 |
lora_trigger_dict = {"None": ["", "", "", "", ""], "": ["", "", "", "", ""]}
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
|
|
|
|
|
|
|
|
|
| 309 |
|
| 310 |
|
| 311 |
civitai_not_exists_list = []
|
|
@@ -332,7 +343,7 @@ def get_civitai_info(path):
|
|
| 332 |
url = base_url + hash_sha256
|
| 333 |
try:
|
| 334 |
r = session.get(url, params=params, headers=headers, stream=True, timeout=(3.0, 15))
|
| 335 |
-
except
|
| 336 |
return ["", "", "", "", ""]
|
| 337 |
if not r.ok: return None
|
| 338 |
json = r.json()
|
|
@@ -357,6 +368,13 @@ def update_lora_dict(path):
|
|
| 357 |
lora_trigger_dict[key] = items
|
| 358 |
|
| 359 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 360 |
def get_lora_tupled_list(lora_model_list):
|
| 361 |
global lora_trigger_dict
|
| 362 |
if not lora_model_list: return []
|
|
@@ -389,7 +407,7 @@ def set_lora_trigger(lora_gui: str):
|
|
| 389 |
gr.update(value="", visible=False), gr.update(value="")
|
| 390 |
path = Path(lora_gui)
|
| 391 |
new_path = Path(f'{path.parent.name}/{escape_lora_basename(path.stem)}{path.suffix}')
|
| 392 |
-
if not new_path.stem in lora_trigger_dict.keys() and not str(path) in set(
|
| 393 |
return gr.update(value="", visible=False), gr.update(visible=False),\
|
| 394 |
gr.update(value="", visible=False), gr.update(value="")
|
| 395 |
if not new_path.exists():
|
|
@@ -416,7 +434,7 @@ def set_lora_trigger(lora_gui: str):
|
|
| 416 |
elif items[3]:
|
| 417 |
md = f'[LoRA Model URL]({items[3]})'
|
| 418 |
if tag and flag:
|
| 419 |
-
new_lora_model_list =
|
| 420 |
return gr.update(value=tag, label=label, visible=True), gr.update(visible=True),\
|
| 421 |
gr.update(value=md, visible=True), gr.update(value=str(new_path), choices=get_lora_tupled_list(new_lora_model_list))
|
| 422 |
elif tag:
|
|
@@ -456,9 +474,7 @@ def move_file_lora(filepaths):
|
|
| 456 |
path.resolve().rename(newpath.resolve())
|
| 457 |
update_lora_dict(str(newpath))
|
| 458 |
|
| 459 |
-
new_lora_model_list =
|
| 460 |
-
new_lora_model_list.insert(0, "None")
|
| 461 |
-
new_lora_model_list.insert(0, "")
|
| 462 |
|
| 463 |
return gr.update(
|
| 464 |
choices=get_lora_tupled_list(new_lora_model_list), value=new_lora_model_list[-1]
|
|
@@ -488,7 +504,7 @@ def search_lora_on_civitai(query: str, allow_model: list[str]):
|
|
| 488 |
session.mount("https://", HTTPAdapter(max_retries=retries))
|
| 489 |
try:
|
| 490 |
r = session.get(base_url, params=params, headers=headers, stream=True, timeout=(3.0, 30))
|
| 491 |
-
except
|
| 492 |
return None
|
| 493 |
if not r.ok: return None
|
| 494 |
json = r.json()
|
|
@@ -781,10 +797,11 @@ def set_quick_presets(genre:str = "None", type:str = "Auto", speed:str = "None",
|
|
| 781 |
|
| 782 |
|
| 783 |
textual_inversion_dict = {}
|
| 784 |
-
|
| 785 |
-
textual_inversion_dict =
|
| 786 |
-
|
| 787 |
-
|
|
|
|
| 788 |
textual_inversion_file_token_list = []
|
| 789 |
|
| 790 |
|
|
|
|
|
|
|
| 1 |
import json
|
| 2 |
import gradio as gr
|
|
|
|
| 3 |
from huggingface_hub import HfApi
|
|
|
|
| 4 |
from pathlib import Path
|
| 5 |
|
| 6 |
+
from env import (
|
| 7 |
+
HF_LORA_PRIVATE_REPOS1,
|
| 8 |
+
HF_LORA_PRIVATE_REPOS2,
|
| 9 |
+
HF_MODEL_USER_EX,
|
| 10 |
+
HF_MODEL_USER_LIKES,
|
| 11 |
+
directory_loras,
|
| 12 |
+
hf_read_token,
|
| 13 |
+
)
|
| 14 |
|
| 15 |
def get_user_agent():
|
| 16 |
return 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:127.0) Gecko/20100101 Firefox/127.0'
|
|
|
|
| 101 |
return model_list
|
| 102 |
|
| 103 |
|
| 104 |
+
private_lora_model_list = []
|
| 105 |
def get_private_lora_model_lists():
|
| 106 |
+
global private_lora_model_list
|
| 107 |
+
if len(private_lora_model_list) != 0: return private_lora_model_list
|
| 108 |
models1 = []
|
| 109 |
models2 = []
|
| 110 |
for repo in HF_LORA_PRIVATE_REPOS1:
|
|
|
|
| 112 |
for repo in HF_LORA_PRIVATE_REPOS2:
|
| 113 |
models2.extend(get_private_model_list(repo, directory_loras))
|
| 114 |
models = list_uniq(models1 + sorted(models2))
|
| 115 |
+
private_lora_model_list = models
|
| 116 |
return models
|
| 117 |
|
| 118 |
|
|
|
|
| 141 |
api = HfApi()
|
| 142 |
model_ids = []
|
| 143 |
try:
|
| 144 |
+
models_likes = []
|
| 145 |
+
for author in HF_MODEL_USER_LIKES:
|
| 146 |
+
models_likes.extend(api.list_models(author=author, cardData=True, sort="likes"))
|
| 147 |
+
models_ex = []
|
| 148 |
+
for author in HF_MODEL_USER_EX:
|
| 149 |
+
models_ex = api.list_models(author=author, cardData=True, sort="last_modified")
|
| 150 |
except Exception as e:
|
| 151 |
return model_ids
|
| 152 |
+
for model in models_likes:
|
| 153 |
model_ids.append(model.id) if not model.private else ""
|
| 154 |
anime_models = []
|
| 155 |
real_models = []
|
| 156 |
+
for model in models_ex:
|
| 157 |
if not model.private:
|
| 158 |
anime_models.append(model.id) if 'anime' in model.tags else real_models.append(model.id)
|
| 159 |
model_ids.extend(anime_models)
|
|
|
|
| 226 |
output_paths = []
|
| 227 |
for image in images:
|
| 228 |
filename = basename + str(i) + ".png"
|
| 229 |
+
i += 1
|
| 230 |
+
oldpath = Path(image[0])
|
| 231 |
+
newpath = oldpath
|
| 232 |
+
if oldpath.exists():
|
| 233 |
+
newpath = oldpath.resolve().rename(Path(filename).resolve())
|
| 234 |
output_paths.append(str(newpath))
|
| 235 |
output_images.append((str(newpath), str(filename)))
|
|
|
|
| 236 |
progress(1, desc="Gallery updated.")
|
| 237 |
+
return gr.update(value=output_images), gr.update(value=output_paths), gr.update(visible=True)
|
| 238 |
|
| 239 |
|
| 240 |
optimization_list = {
|
|
|
|
| 310 |
|
| 311 |
|
| 312 |
lora_trigger_dict = {"None": ["", "", "", "", ""], "": ["", "", "", "", ""]}
|
| 313 |
+
try:
|
| 314 |
+
with open('lora_dict.json', encoding='utf-8') as f:
|
| 315 |
+
temp_dict = json.load(f)
|
| 316 |
+
for k, v in temp_dict.items():
|
| 317 |
+
lora_trigger_dict[escape_lora_basename(k)] = v
|
| 318 |
+
except Exception:
|
| 319 |
+
pass
|
| 320 |
|
| 321 |
|
| 322 |
civitai_not_exists_list = []
|
|
|
|
| 343 |
url = base_url + hash_sha256
|
| 344 |
try:
|
| 345 |
r = session.get(url, params=params, headers=headers, stream=True, timeout=(3.0, 15))
|
| 346 |
+
except Exception as e:
|
| 347 |
return ["", "", "", "", ""]
|
| 348 |
if not r.ok: return None
|
| 349 |
json = r.json()
|
|
|
|
| 368 |
lora_trigger_dict[key] = items
|
| 369 |
|
| 370 |
|
| 371 |
+
def get_lora_model_list():
|
| 372 |
+
loras = list_uniq(get_private_lora_model_lists() + get_local_model_list(directory_loras))
|
| 373 |
+
loras.insert(0, "None")
|
| 374 |
+
loras.insert(0, "")
|
| 375 |
+
return loras
|
| 376 |
+
|
| 377 |
+
|
| 378 |
def get_lora_tupled_list(lora_model_list):
|
| 379 |
global lora_trigger_dict
|
| 380 |
if not lora_model_list: return []
|
|
|
|
| 407 |
gr.update(value="", visible=False), gr.update(value="")
|
| 408 |
path = Path(lora_gui)
|
| 409 |
new_path = Path(f'{path.parent.name}/{escape_lora_basename(path.stem)}{path.suffix}')
|
| 410 |
+
if not new_path.stem in lora_trigger_dict.keys() and not str(path) in set(get_lora_model_list()):
|
| 411 |
return gr.update(value="", visible=False), gr.update(visible=False),\
|
| 412 |
gr.update(value="", visible=False), gr.update(value="")
|
| 413 |
if not new_path.exists():
|
|
|
|
| 434 |
elif items[3]:
|
| 435 |
md = f'[LoRA Model URL]({items[3]})'
|
| 436 |
if tag and flag:
|
| 437 |
+
new_lora_model_list = get_lora_model_list()
|
| 438 |
return gr.update(value=tag, label=label, visible=True), gr.update(visible=True),\
|
| 439 |
gr.update(value=md, visible=True), gr.update(value=str(new_path), choices=get_lora_tupled_list(new_lora_model_list))
|
| 440 |
elif tag:
|
|
|
|
| 474 |
path.resolve().rename(newpath.resolve())
|
| 475 |
update_lora_dict(str(newpath))
|
| 476 |
|
| 477 |
+
new_lora_model_list = get_lora_model_list()
|
|
|
|
|
|
|
| 478 |
|
| 479 |
return gr.update(
|
| 480 |
choices=get_lora_tupled_list(new_lora_model_list), value=new_lora_model_list[-1]
|
|
|
|
| 504 |
session.mount("https://", HTTPAdapter(max_retries=retries))
|
| 505 |
try:
|
| 506 |
r = session.get(base_url, params=params, headers=headers, stream=True, timeout=(3.0, 30))
|
| 507 |
+
except Exception as e:
|
| 508 |
return None
|
| 509 |
if not r.ok: return None
|
| 510 |
json = r.json()
|
|
|
|
| 797 |
|
| 798 |
|
| 799 |
textual_inversion_dict = {}
|
| 800 |
+
try:
|
| 801 |
+
with open('textual_inversion_dict.json', encoding='utf-8') as f:
|
| 802 |
+
textual_inversion_dict = json.load(f)
|
| 803 |
+
except Exception:
|
| 804 |
+
pass
|
| 805 |
textual_inversion_file_token_list = []
|
| 806 |
|
| 807 |
|