r3gm commited on
Commit
4b273e2
1 Parent(s): b647d6d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +277 -403
app.py CHANGED
@@ -1,14 +1,11 @@
1
  import spaces
2
  import os
3
  from stablepy import Model_Diffusers
4
- from stablepy.diffusers_vanilla.model import scheduler_names
5
  from stablepy.diffusers_vanilla.style_prompt_config import STYLE_NAMES
6
  from stablepy.diffusers_vanilla.constants import FLUX_CN_UNION_MODES
7
  import torch
8
  import re
9
  from huggingface_hub import HfApi
10
- import shutil
11
- import random
12
  from stablepy import (
13
  CONTROLNET_MODEL_IDS,
14
  VALID_TASKS,
@@ -24,9 +21,77 @@ from stablepy import (
24
  SD15_TASKS,
25
  SDXL_TASKS,
26
  )
27
- import urllib.parse
28
 
29
- preprocessor_controlnet = {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  "openpose": [
31
  "Openpose",
32
  "None",
@@ -99,7 +164,7 @@ preprocessor_controlnet = {
99
 
100
  }
101
 
102
- task_stablepy = {
103
  'txt2img': 'txt2img',
104
  'img2img': 'img2img',
105
  'inpaint': 'inpaint',
@@ -125,7 +190,35 @@ task_stablepy = {
125
  'tile ControlNet': 'tile',
126
  }
127
 
128
- TASK_MODEL_LIST = list(task_stablepy.keys())
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
 
130
 
131
  def download_things(directory, url, hf_token="", civitai_api_key=""):
@@ -164,7 +257,7 @@ def get_model_list(directory_path):
164
 
165
  for filename in os.listdir(directory_path):
166
  if os.path.splitext(filename)[1] in valid_extensions:
167
- name_without_extension = os.path.splitext(filename)[0]
168
  file_path = os.path.join(directory_path, filename)
169
  # model_list.append((name_without_extension, file_path))
170
  model_list.append(file_path)
@@ -179,84 +272,16 @@ os.makedirs(directory_loras, exist_ok=True)
179
  directory_vaes = 'vaes'
180
  os.makedirs(directory_vaes, exist_ok=True)
181
 
182
- # - **Download SD 1.5 Models**
183
- download_model = "https://civitai.com/api/download/models/574369, https://huggingface.co/TechnoByte/MilkyWonderland/resolve/main/milkyWonderland_v40.safetensors"
184
- # - **Download VAEs**
185
- download_vae = "https://huggingface.co/nubby/blessed-sdxl-vae-fp16-fix/resolve/main/sdxl_vae-fp16fix-c-1.1-b-0.5.safetensors?download=true, https://huggingface.co/nubby/blessed-sdxl-vae-fp16-fix/resolve/main/sdxl_vae-fp16fix-blessed.safetensors?download=true, https://huggingface.co/digiplay/VAE/resolve/main/vividReal_v20.safetensors?download=true, https://huggingface.co/fp16-guy/anything_kl-f8-anime2_vae-ft-mse-840000-ema-pruned_blessed_clearvae_fp16_cleaned/resolve/main/vae-ft-mse-840000-ema-pruned_fp16.safetensors?download=true"
186
- # - **Download LoRAs**
187
- download_lora = "https://civitai.com/api/download/models/28907, https://huggingface.co/Leopain/color/resolve/main/Coloring_book_-_LineArt.safetensors, https://civitai.com/api/download/models/135867, https://civitai.com/api/download/models/145907, https://huggingface.co/Linaqruf/anime-detailer-xl-lora/resolve/main/anime-detailer-xl.safetensors?download=true, https://huggingface.co/Linaqruf/style-enhancer-xl-lora/resolve/main/style-enhancer-xl.safetensors?download=true, https://civitai.com/api/download/models/28609, https://huggingface.co/ByteDance/Hyper-SD/resolve/main/Hyper-SD15-8steps-CFG-lora.safetensors?download=true, https://huggingface.co/ByteDance/Hyper-SD/resolve/main/Hyper-SDXL-8steps-CFG-lora.safetensors?download=true"
188
- load_diffusers_format_model = [
189
- 'stabilityai/stable-diffusion-xl-base-1.0',
190
- 'black-forest-labs/FLUX.1-dev',
191
- 'John6666/blue-pencil-flux1-v021-fp8-flux',
192
- 'John6666/wai-ani-flux-v10forfp8-fp8-flux',
193
- 'John6666/xe-anime-flux-v04-fp8-flux',
194
- 'cagliostrolab/animagine-xl-3.1',
195
- 'John6666/epicrealism-xl-v8kiss-sdxl',
196
- 'misri/epicrealismXL_v7FinalDestination',
197
- 'misri/juggernautXL_juggernautX',
198
- 'misri/zavychromaxl_v80',
199
- 'SG161222/RealVisXL_V4.0',
200
- 'SG161222/RealVisXL_V5.0',
201
- 'misri/newrealityxlAllInOne_Newreality40',
202
- 'eienmojiki/Anything-XL',
203
- 'eienmojiki/Starry-XL-v5.2',
204
- 'gsdf/CounterfeitXL',
205
- 'KBlueLeaf/Kohaku-XL-Zeta',
206
- 'John6666/silvermoon-mix-01xl-v11-sdxl',
207
- 'WhiteAiZ/autismmixSDXL_autismmixConfetti_diffusers',
208
- 'kitty7779/ponyDiffusionV6XL',
209
- 'GraydientPlatformAPI/aniverse-pony',
210
- 'John6666/mistoon-anime-ponyalpha-sdxl',
211
- 'John6666/ebara-mfcg-pony-mix-v12-sdxl',
212
- 'John6666/t-ponynai3-v51-sdxl',
213
- 'John6666/mala-anime-mix-nsfw-pony-xl-v5-sdxl',
214
- 'John6666/wai-real-mix-v11-sdxl',
215
- 'John6666/cyberrealistic-pony-v63-sdxl',
216
- 'GraydientPlatformAPI/realcartoon-pony-diffusion',
217
- 'John6666/nova-anime-xl-pony-v5-sdxl',
218
- 'John6666/autismmix-sdxl-autismmix-pony-sdxl',
219
- 'yodayo-ai/kivotos-xl-2.0',
220
- 'yodayo-ai/holodayo-xl-2.1',
221
- 'yodayo-ai/clandestine-xl-1.0',
222
- 'digiplay/majicMIX_sombre_v2',
223
- 'digiplay/majicMIX_realistic_v6',
224
- 'digiplay/majicMIX_realistic_v7',
225
- 'digiplay/DreamShaper_8',
226
- 'digiplay/BeautifulArt_v1',
227
- 'digiplay/DarkSushi2.5D_v1',
228
- 'digiplay/darkphoenix3D_v1.1',
229
- 'digiplay/BeenYouLiteL11_diffusers',
230
- 'Yntec/RevAnimatedV2Rebirth',
231
- 'youknownothing/cyberrealistic_v50',
232
- 'youknownothing/deliberate-v6',
233
- 'GraydientPlatformAPI/deliberate-cyber3',
234
- 'GraydientPlatformAPI/picx-real',
235
- 'GraydientPlatformAPI/perfectworld6',
236
- 'emilianJR/epiCRealism',
237
- 'votepurchase/counterfeitV30_v30',
238
- 'votepurchase/ChilloutMix',
239
- 'Meina/MeinaMix_V11',
240
- 'Meina/MeinaUnreal_V5',
241
- 'Meina/MeinaPastel_V7',
242
- 'GraydientPlatformAPI/realcartoon3d-17',
243
- 'GraydientPlatformAPI/realcartoon-pixar11',
244
- 'GraydientPlatformAPI/realcartoon-real17',
245
- ]
246
-
247
- CIVITAI_API_KEY = os.environ.get("CIVITAI_API_KEY")
248
- hf_token = os.environ.get("HF_READ_TOKEN")
249
-
250
  # Download stuffs
251
  for url in [url.strip() for url in download_model.split(',')]:
252
  if not os.path.exists(f"./models/{url.split('/')[-1]}"):
253
- download_things(directory_models, url, hf_token, CIVITAI_API_KEY)
254
  for url in [url.strip() for url in download_vae.split(',')]:
255
  if not os.path.exists(f"./vaes/{url.split('/')[-1]}"):
256
- download_things(directory_vaes, url, hf_token, CIVITAI_API_KEY)
257
  for url in [url.strip() for url in download_lora.split(',')]:
258
  if not os.path.exists(f"./loras/{url.split('/')[-1]}"):
259
- download_things(directory_loras, url, hf_token, CIVITAI_API_KEY)
260
 
261
  # Download Embeddings
262
  directory_embeds = 'embedings'
@@ -269,7 +294,7 @@ download_embeds = [
269
 
270
  for url_embed in download_embeds:
271
  if not os.path.exists(f"./embedings/{url_embed.split('/')[-1]}"):
272
- download_things(directory_embeds, url_embed, hf_token, CIVITAI_API_KEY)
273
 
274
  # Build list models
275
  embed_list = get_model_list(directory_embeds)
@@ -280,70 +305,71 @@ lora_model_list.insert(0, "None")
280
  vae_model_list = get_model_list(directory_vaes)
281
  vae_model_list.insert(0, "None")
282
 
 
283
 
284
- def get_my_lora(link_url):
285
- for url in [url.strip() for url in link_url.split(',')]:
286
- if not os.path.exists(f"./loras/{url.split('/')[-1]}"):
287
- download_things(directory_loras, url, hf_token, CIVITAI_API_KEY)
288
- new_lora_model_list = get_model_list(directory_loras)
289
- new_lora_model_list.insert(0, "None")
 
 
 
 
 
 
 
290
 
291
- return gr.update(
292
- choices=new_lora_model_list
293
- ), gr.update(
294
- choices=new_lora_model_list
295
- ), gr.update(
296
- choices=new_lora_model_list
297
- ), gr.update(
298
- choices=new_lora_model_list
299
- ), gr.update(
300
- choices=new_lora_model_list
301
- ),
302
 
 
 
 
 
303
 
304
- print('\033[33m🏁 Download and listing of valid models completed.\033[0m')
 
 
305
 
306
- upscaler_dict_gui = {
307
- None: None,
308
- "Lanczos": "Lanczos",
309
- "Nearest": "Nearest",
310
- 'Latent': 'Latent',
311
- 'Latent (antialiased)': 'Latent (antialiased)',
312
- 'Latent (bicubic)': 'Latent (bicubic)',
313
- 'Latent (bicubic antialiased)': 'Latent (bicubic antialiased)',
314
- 'Latent (nearest)': 'Latent (nearest)',
315
- 'Latent (nearest-exact)': 'Latent (nearest-exact)',
316
- "RealESRGAN_x4plus": "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth",
317
- "RealESRNet_x4plus": "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.1/RealESRNet_x4plus.pth",
318
- "RealESRGAN_x4plus_anime_6B": "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth",
319
- "RealESRGAN_x2plus": "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.1/RealESRGAN_x2plus.pth",
320
- "realesr-animevideov3": "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-animevideov3.pth",
321
- "realesr-general-x4v3": "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-general-x4v3.pth",
322
- "realesr-general-wdn-x4v3": "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-general-wdn-x4v3.pth",
323
- "4x-UltraSharp": "https://huggingface.co/Shandypur/ESRGAN-4x-UltraSharp/resolve/main/4x-UltraSharp.pth",
324
- "4x_foolhardy_Remacri": "https://huggingface.co/FacehugmanIII/4x_foolhardy_Remacri/resolve/main/4x_foolhardy_Remacri.pth",
325
- "Remacri4xExtraSmoother": "https://huggingface.co/hollowstrawberry/upscalers-backup/resolve/main/ESRGAN/Remacri%204x%20ExtraSmoother.pth",
326
- "AnimeSharp4x": "https://huggingface.co/hollowstrawberry/upscalers-backup/resolve/main/ESRGAN/AnimeSharp%204x.pth",
327
- "lollypop": "https://huggingface.co/hollowstrawberry/upscalers-backup/resolve/main/ESRGAN/lollypop.pth",
328
- "RealisticRescaler4x": "https://huggingface.co/hollowstrawberry/upscalers-backup/resolve/main/ESRGAN/RealisticRescaler%204x.pth",
329
- "NickelbackFS4x": "https://huggingface.co/hollowstrawberry/upscalers-backup/resolve/main/ESRGAN/NickelbackFS%204x.pth"
330
  }
331
 
332
- upscaler_keys = list(upscaler_dict_gui.keys())
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
333
 
334
 
335
  def extract_parameters(input_string):
336
  parameters = {}
337
  input_string = input_string.replace("\n", "")
338
 
339
- if not "Negative prompt:" in input_string:
340
  print("Negative prompt not detected")
341
  parameters["prompt"] = input_string
342
  return parameters
343
 
344
  parm = input_string.split("Negative prompt:")
345
  parameters["prompt"] = parm[0]
346
- if not "Steps:" in parm[1]:
347
  print("Steps not detected")
348
  parameters["neg_prompt"] = parm[1]
349
  return parameters
@@ -372,27 +398,24 @@ def extract_parameters(input_string):
372
  return parameters
373
 
374
 
375
- #######################
376
- # GUI
377
- #######################
378
- import spaces
379
- import gradio as gr
380
- import logging
381
- logging.getLogger("diffusers").setLevel(logging.ERROR)
382
- import diffusers
383
- diffusers.utils.logging.set_verbosity(40)
384
- import warnings
385
- warnings.filterwarnings(action="ignore", category=FutureWarning, module="diffusers")
386
- warnings.filterwarnings(action="ignore", category=UserWarning, module="diffusers")
387
- warnings.filterwarnings(action="ignore", category=FutureWarning, module="transformers")
388
- from stablepy import logger
389
-
390
- logger.setLevel(logging.DEBUG)
391
 
392
- msg_inc_vae = (
393
- "Use the right VAE for your model to maintain image quality. The wrong"
394
- " VAE can lead to poor results, like blurriness in the generated images."
395
- )
 
 
 
 
 
 
 
396
 
397
 
398
  def info_html(json_data, title, subtitle):
@@ -442,7 +465,7 @@ class GuiSD:
442
  model_type = get_model_type(model_name)
443
 
444
  if vae_model:
445
- vae_type = "SXDL" if "sdxl" in vae_model.lower() else "SD 1.5"
446
  if model_type != vae_type:
447
  gr.Info(msg_inc_vae)
448
 
@@ -451,11 +474,12 @@ class GuiSD:
451
 
452
  self.model.load_pipe(
453
  model_name,
454
- task_name=task_stablepy[task],
455
  vae_model=vae_model,
456
  type_model_precision=dtype_model,
457
  retain_task_model_in_cache=False,
458
  )
 
459
  yield f"Model loaded: {model_name}"
460
 
461
  @spaces.GPU(duration=59)
@@ -573,7 +597,7 @@ class GuiSD:
573
 
574
  print("Config model:", model_name, vae_model, loras_list)
575
 
576
- task = task_stablepy[task]
577
 
578
  params_ip_img = []
579
  params_ip_msk = []
@@ -603,16 +627,16 @@ class GuiSD:
603
  if task == "inpaint" and not image_mask:
604
  raise ValueError("No mask image found: Specify one in 'Image Mask'")
605
 
606
- if upscaler_model_path in upscaler_keys[:9]:
607
  upscaler_model = upscaler_model_path
608
  else:
609
  directory_upscalers = 'upscalers'
610
  os.makedirs(directory_upscalers, exist_ok=True)
611
 
612
- url_upscaler = upscaler_dict_gui[upscaler_model_path]
613
 
614
  if not os.path.exists(f"./upscalers/{url_upscaler.split('/')[-1]}"):
615
- download_things(directory_upscalers, url_upscaler, hf_token)
616
 
617
  upscaler_model = f"./upscalers/{url_upscaler.split('/')[-1]}"
618
 
@@ -752,30 +776,6 @@ class GuiSD:
752
  yield img, info_state
753
 
754
 
755
- sd_gen = GuiSD()
756
-
757
- CSS = """
758
- .contain { display: flex; flex-direction: column; }
759
- #component-0 { height: 100%; }
760
- #gallery { flex-grow: 1; }
761
- """
762
- SDXL_TASK = [k for k, v in task_stablepy.items() if v in SDXL_TASKS ]
763
- SD_TASK = [k for k, v in task_stablepy.items() if v in SD15_TASKS ]
764
- FLUX_TASK = list(task_stablepy.keys())[:3] + [k for k, v in task_stablepy.items() if v in FLUX_CN_UNION_MODES.keys() ]
765
-
766
- MODEL_TYPE_TASK = {
767
- "SD 1.5": SD_TASK,
768
- "SDXL": SDXL_TASK,
769
- "FLUX": FLUX_TASK,
770
- }
771
-
772
- MODEL_TYPE_CLASS = {
773
- "diffusers:StableDiffusionPipeline": "SD 1.5",
774
- "diffusers:StableDiffusionXLPipeline": "SDXL",
775
- "diffusers:FluxPipeline": "FLUX",
776
- }
777
-
778
-
779
  def update_task_options(model_name, task_name):
780
  new_choices = MODEL_TYPE_TASK[get_model_type(model_name)]
781
 
@@ -785,12 +785,33 @@ def update_task_options(model_name, task_name):
785
  return gr.update(value=task_name, choices=new_choices)
786
 
787
 
788
- POST_PROCESSING_SAMPLER = ["Use same sampler"] + scheduler_names[:-2]
789
 
790
- SUBTITLE_GUI = (
791
- "### This demo uses [diffusers](https://github.com/huggingface/diffusers)"
792
- " to perform different tasks in image generation."
793
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
794
 
795
  with gr.Blocks(theme="NoCrypt/miku", css=CSS) as app:
796
  gr.Markdown("# 🧩 DiffuseCraft")
@@ -856,7 +877,7 @@ with gr.Blocks(theme="NoCrypt/miku", css=CSS) as app:
856
  "height": gr.update(value=1024),
857
  "Seed": gr.update(value=-1),
858
  "Sampler": gr.update(value="Euler a"),
859
- "scale": gr.update(value=7.5), # cfg
860
  "skip": gr.update(value=True),
861
  }
862
  valid_keys = list(valid_receptors.keys())
@@ -866,15 +887,15 @@ with gr.Blocks(theme="NoCrypt/miku", css=CSS) as app:
866
  # print(val)
867
  if key in valid_keys:
868
  if key == "Sampler":
869
- if val not in scheduler_names:
870
- continue
871
  elif key == "skip":
872
- if int(val) >= 2:
873
- val = True
874
  if key == "prompt":
875
- if ">" in val and "<" in val:
876
- val = re.sub(r'<[^>]+>', '', val)
877
- print("Removed LoRA written in the prompt")
878
  if key in ["prompt", "neg_prompt"]:
879
  val = val.strip()
880
  if key in ["Steps", "width", "height", "Seed"]:
@@ -889,7 +910,7 @@ with gr.Blocks(theme="NoCrypt/miku", css=CSS) as app:
889
  return [value for value in valid_receptors.values()]
890
 
891
  set_params_gui.click(
892
- run_set_params_gui, [prompt_gui],[
893
  prompt_gui,
894
  neg_prompt_gui,
895
  steps_gui,
@@ -928,7 +949,7 @@ with gr.Blocks(theme="NoCrypt/miku", css=CSS) as app:
928
 
929
  with gr.Accordion("Hires fix", open=False, visible=True):
930
 
931
- upscaler_model_path_gui = gr.Dropdown(label="Upscaler", choices=upscaler_keys, value=upscaler_keys[0])
932
  upscaler_increases_size_gui = gr.Slider(minimum=1.1, maximum=6., step=0.1, value=1.4, label="Upscale by")
933
  esrgan_tile_gui = gr.Slider(minimum=0, value=100, maximum=500, step=1, label="ESRGAN Tile")
934
  esrgan_tile_overlap_gui = gr.Slider(minimum=1, maximum=200, step=1, value=10, label="ESRGAN Tile Overlap")
@@ -992,14 +1013,14 @@ with gr.Blocks(theme="NoCrypt/miku", css=CSS) as app:
992
  info="This option adjusts the level of changes for img2img and inpainting."
993
  )
994
  image_resolution_gui = gr.Slider(minimum=64, maximum=2048, step=64, value=1024, label="Image Resolution")
995
- preprocessor_name_gui = gr.Dropdown(label="Preprocessor Name", choices=preprocessor_controlnet["canny"])
996
 
997
  def change_preprocessor_choices(task):
998
- task = task_stablepy[task]
999
- if task in preprocessor_controlnet.keys():
1000
- choices_task = preprocessor_controlnet[task]
1001
  else:
1002
- choices_task = preprocessor_controlnet["canny"]
1003
  return gr.update(choices=choices_task, value=choices_task[0])
1004
 
1005
  task_gui.change(
@@ -1025,7 +1046,7 @@ with gr.Blocks(theme="NoCrypt/miku", css=CSS) as app:
1025
 
1026
  try:
1027
  style_names_found = sd_gen.model.STYLE_NAMES
1028
- except:
1029
  style_names_found = STYLE_NAMES
1030
 
1031
  style_prompt_gui = gr.Dropdown(
@@ -1123,7 +1144,7 @@ with gr.Blocks(theme="NoCrypt/miku", css=CSS) as app:
1123
  3. ControlNet Canny SDXL
1124
  4. Optical pattern (Optical illusion) SDXL
1125
  5. Convert an image to a coloring drawing
1126
- 6. ControlNet OpenPose SD 1.5
1127
 
1128
  - Different tasks can be performed, such as img2img or using the IP adapter, to preserve a person's appearance or a specific style based on an image.
1129
  """
@@ -1131,309 +1152,162 @@ with gr.Blocks(theme="NoCrypt/miku", css=CSS) as app:
1131
  gr.Examples(
1132
  examples=[
1133
  [
1134
- "1girl, souryuu asuka langley, neon genesis evangelion, plugsuit, pilot suit, red bodysuit, sitting, crossing legs, black eye patch, cat hat, throne, symmetrical, looking down, from bottom, looking at viewer, outdoors, masterpiece, best quality, very aesthetic, absurdres",
1135
- "nsfw, lowres, (bad), text, error, fewer, extra, missing, worst quality, jpeg artifacts, low quality, watermark, unfinished, displeasing, oldest, early, chromatic aberration, signature, extra digits, artistic error, username, scan, [abstract]",
1136
- 1,
1137
- 30,
1138
- 7.5,
1139
- True,
1140
  -1,
1141
  "None",
1142
- 1.0,
1143
- "None",
1144
- 1.0,
1145
- "None",
1146
- 1.0,
1147
- "None",
1148
- 1.0,
1149
- "None",
1150
- 1.0,
1151
  "Euler a",
1152
  1152,
1153
  896,
1154
  "cagliostrolab/animagine-xl-3.1",
1155
- None, # vae
1156
  "txt2img",
1157
- None, # img conttol
1158
- "Canny", # preprocessor
1159
- 512, # preproc resolution
1160
- 1024, # img resolution
1161
- None, # Style prompt
1162
- None, # Style json
1163
- None, # img Mask
1164
- 0.35, # strength
1165
- 100, # low th canny
1166
- 200, # high th canny
1167
- 0.1, # value mstd
1168
- 0.1, # distance mstd
1169
- 1.0, # cn scale
1170
- 0., # cn start
1171
- 1., # cn end
1172
- False, # ti
1173
  "Classic",
1174
  "Nearest",
1175
  ],
1176
  [
1177
- "a tiny astronaut hatching from an egg on the moon",
1178
  "",
1179
- 1,
1180
- 28,
1181
  3.5,
1182
- True,
1183
  -1,
1184
  "None",
1185
- 1.0,
1186
- "None",
1187
- 1.0,
1188
- "None",
1189
- 1.0,
1190
- "None",
1191
- 1.0,
1192
- "None",
1193
- 1.0,
1194
  "Euler a",
1195
- 1024,
1196
- 1024,
1197
  "black-forest-labs/FLUX.1-dev",
1198
- None, # vae
1199
  "txt2img",
1200
- None, # img conttol
1201
- "Canny", # preprocessor
1202
- 512, # preproc resolution
1203
- 1024, # img resolution
1204
- None, # Style prompt
1205
- None, # Style json
1206
- None, # img Mask
1207
- 0.35, # strength
1208
- 100, # low th canny
1209
- 200, # high th canny
1210
- 0.1, # value mstd
1211
- 0.1, # distance mstd
1212
- 1.0, # cn scale
1213
- 0., # cn start
1214
- 1., # cn end
1215
- False, # ti
1216
  "Classic",
1217
  None,
1218
  ],
1219
  [
1220
- "((masterpiece)), best quality, blonde disco girl, detailed face, realistic face, realistic hair, dynamic pose, pink pvc, intergalactic disco background, pastel lights, dynamic contrast, airbrush, fine detail, 70s vibe, midriff ",
1221
  "(worst quality:1.2), (bad quality:1.2), (poor quality:1.2), (missing fingers:1.2), bad-artist-anime, bad-artist, bad-picture-chill-75v",
1222
- 1,
1223
  48,
1224
  3.5,
1225
- True,
1226
  -1,
1227
  "None",
1228
- 1.0,
1229
- "None",
1230
- 1.0,
1231
- "None",
1232
- 1.0,
1233
- "None",
1234
- 1.0,
1235
- "None",
1236
- 1.0,
1237
  "DPM++ 2M SDE Lu",
1238
  1024,
1239
  1024,
1240
  "misri/epicrealismXL_v7FinalDestination",
1241
- None, # vae
1242
  "canny ControlNet",
1243
- "image.webp", # img conttol
1244
- "Canny", # preprocessor
1245
- 1024, # preproc resolution
1246
- 1024, # img resolution
1247
- None, # Style prompt
1248
- None, # Style json
1249
- None, # img Mask
1250
- 0.35, # strength
1251
- 100, # low th canny
1252
- 200, # high th canny
1253
- 0.1, # value mstd
1254
- 0.1, # distance mstd
1255
- 1.0, # cn scale
1256
- 0., # cn start
1257
- 1., # cn end
1258
- False, # ti
1259
  "Classic",
1260
  None,
1261
  ],
1262
  [
1263
  "cinematic scenery old city ruins",
1264
  "(worst quality, low quality, illustration, 3d, 2d, painting, cartoons, sketch), (illustration, 3d, 2d, painting, cartoons, sketch, blurry, film grain, noise), (low quality, worst quality:1.2)",
1265
- 1,
1266
  50,
1267
- 4.,
1268
- True,
1269
  -1,
1270
  "None",
1271
- 1.0,
1272
- "None",
1273
- 1.0,
1274
- "None",
1275
- 1.0,
1276
- "None",
1277
- 1.0,
1278
- "None",
1279
- 1.0,
1280
  "Euler a",
1281
  1024,
1282
  1024,
1283
  "misri/juggernautXL_juggernautX",
1284
- None, # vae
1285
  "optical pattern ControlNet",
1286
- "spiral_no_transparent.png", # img conttol
1287
- "Canny", # preprocessor
1288
- 512, # preproc resolution
1289
- 1024, # img resolution
1290
- None, # Style prompt
1291
- None, # Style json
1292
- None, # img Mask
1293
- 0.35, # strength
1294
- 100, # low th canny
1295
- 200, # high th canny
1296
- 0.1, # value mstd
1297
- 0.1, # distance mstd
1298
- 1.0, # cn scale
1299
- 0.05, # cn start
1300
- 0.75, # cn end
1301
- False, # ti
1302
  "Classic",
1303
  None,
1304
  ],
1305
  [
1306
  "black and white, line art, coloring drawing, clean line art, black strokes, no background, white, black, free lines, black scribbles, on paper, A blend of comic book art and lineart full of black and white color, masterpiece, high-resolution, trending on Pixiv fan box, palette knife, brush strokes, two-dimensional, planar vector, T-shirt design, stickers, and T-shirt design, vector art, fantasy art, Adobe Illustrator, hand-painted, digital painting, low polygon, soft lighting, aerial view, isometric style, retro aesthetics, 8K resolution, black sketch lines, monochrome, invert color",
1307
  "color, red, green, yellow, colored, duplicate, blurry, abstract, disfigured, deformed, animated, toy, figure, framed, 3d, bad art, poorly drawn, extra limbs, close up, b&w, weird colors, blurry, watermark, blur haze, 2 heads, long neck, watermark, elongated body, cropped image, out of frame, draft, deformed hands, twisted fingers, double image, malformed hands, multiple heads, extra limb, ugly, poorly drawn hands, missing limb, cut-off, over satured, grain, lowères, bad anatomy, poorly drawn face, mutation, mutated, floating limbs, disconnected limbs, out of focus, long body, disgusting, extra fingers, groos proportions, missing arms, mutated hands, cloned face, missing legs, ugly, tiling, poorly drawn hands, poorly drawn feet, poorly drawn face, out of frame, extra limbs, disfigured, deformed, body out of frame, blurry, bad anatomy, blurred, watermark, grainy, signature, cut off, draft, deformed, blurry, bad anatomy, disfigured, poorly drawn face, mutation, bluelish, blue",
1308
- 1,
1309
  20,
1310
- 4.,
1311
- True,
1312
  -1,
1313
  "loras/Coloring_book_-_LineArt.safetensors",
1314
  1.0,
1315
- "None",
1316
- 1.0,
1317
- "None",
1318
- 1.0,
1319
- "None",
1320
- 1.0,
1321
- "None",
1322
- 1.0,
1323
  "DPM++ 2M SDE Karras",
1324
  1024,
1325
  1024,
1326
  "cagliostrolab/animagine-xl-3.1",
1327
- None, # vae
1328
  "lineart ControlNet",
1329
- "color_image.png", # img conttol
1330
- "Lineart", # preprocessor
1331
- 512, # preproc resolution
1332
- 896, # img resolution
1333
- None, # Style prompt
1334
- None, # Style json
1335
- None, # img Mask
1336
- 0.35, # strength
1337
- 100, # low th canny
1338
- 200, # high th canny
1339
- 0.1, # value mstd
1340
- 0.1, # distance mstd
1341
- 1.0, # cn scale
1342
- 0., # cn start
1343
- 1., # cn end
1344
- False, # ti
1345
  "Compel",
1346
  None,
1347
  ],
1348
  [
1349
  "1girl,face,curly hair,red hair,white background,",
1350
  "(worst quality:2),(low quality:2),(normal quality:2),lowres,watermark,",
1351
- 1,
1352
  38,
1353
- 5.,
1354
- True,
1355
  -1,
1356
  "None",
1357
- 1.0,
1358
- "None",
1359
- 1.0,
1360
- "None",
1361
- 1.0,
1362
- "None",
1363
- 1.0,
1364
- "None",
1365
- 1.0,
1366
  "DPM++ 2M SDE Karras",
1367
  512,
1368
  512,
1369
  "digiplay/majicMIX_realistic_v7",
1370
- None, # vae
1371
  "openpose ControlNet",
1372
- "image.webp", # img conttol
1373
- "Canny", # preprocessor
1374
- 512, # preproc resolution
1375
- 1024, # img resolution
1376
- None, # Style prompt
1377
- None, # Style json
1378
- None, # img Mask
1379
- 0.35, # strength
1380
- 100, # low th canny
1381
- 200, # high th canny
1382
- 0.1, # value mstd
1383
- 0.1, # distance mstd
1384
- 1.0, # cn scale
1385
- 0., # cn start
1386
- 0.9, # cn end
1387
- False, # ti
1388
  "Compel",
1389
- "Nearest",
1390
  ],
1391
  ],
1392
  fn=sd_gen.generate_pipeline,
1393
  inputs=[
1394
  prompt_gui,
1395
  neg_prompt_gui,
1396
- num_images_gui,
1397
  steps_gui,
1398
  cfg_gui,
1399
- clip_skip_gui,
1400
  seed_gui,
1401
  lora1_gui,
1402
  lora_scale_1_gui,
1403
- lora2_gui,
1404
- lora_scale_2_gui,
1405
- lora3_gui,
1406
- lora_scale_3_gui,
1407
- lora4_gui,
1408
- lora_scale_4_gui,
1409
- lora5_gui,
1410
- lora_scale_5_gui,
1411
  sampler_gui,
1412
  img_height_gui,
1413
  img_width_gui,
1414
  model_name_gui,
1415
- vae_model_gui,
1416
  task_gui,
1417
  image_control,
1418
- preprocessor_name_gui,
1419
- preprocess_resolution_gui,
1420
  image_resolution_gui,
1421
- style_prompt_gui,
1422
- style_json_gui,
1423
- image_mask_gui,
1424
  strength_gui,
1425
- low_threshold_gui,
1426
- high_threshold_gui,
1427
- value_threshold_gui,
1428
- distance_threshold_gui,
1429
  control_net_output_scaling_gui,
1430
  control_net_start_threshold_gui,
1431
  control_net_stop_threshold_gui,
1432
- active_textual_inversion_gui,
1433
  prompt_syntax_gui,
1434
  upscaler_model_path_gui,
1435
  ],
1436
- outputs=[result_images],
1437
  cache_examples=False,
1438
  )
1439
 
@@ -1475,11 +1349,11 @@ with gr.Blocks(theme="NoCrypt/miku", css=CSS) as app:
1475
  # enable crop (or disable it)
1476
  # transforms=["crop"],
1477
  brush=gr.Brush(
1478
- default_size="16", # or leave it as 'auto'
1479
- color_mode="fixed", # 'fixed' hides the user swatches and colorpicker, 'defaults' shows it
1480
  # default_color="black", # html names are supported
1481
  colors=[
1482
- "rgba(0, 0, 0, 1)", # rgb(a)
1483
  "rgba(0, 0, 0, 0.1)",
1484
  "rgba(255, 255, 255, 0.1)",
1485
  # "hsl(360, 120, 120)" # in fact any valid colorstring
@@ -1511,7 +1385,7 @@ with gr.Blocks(theme="NoCrypt/miku", css=CSS) as app:
1511
  queue=True,
1512
  show_progress="minimal",
1513
  ).success(
1514
- fn=sd_gen.generate_pipeline,
1515
  inputs=[
1516
  prompt_gui,
1517
  neg_prompt_gui,
 
1
  import spaces
2
  import os
3
  from stablepy import Model_Diffusers
 
4
  from stablepy.diffusers_vanilla.style_prompt_config import STYLE_NAMES
5
  from stablepy.diffusers_vanilla.constants import FLUX_CN_UNION_MODES
6
  import torch
7
  import re
8
  from huggingface_hub import HfApi
 
 
9
  from stablepy import (
10
  CONTROLNET_MODEL_IDS,
11
  VALID_TASKS,
 
21
  SD15_TASKS,
22
  SDXL_TASKS,
23
  )
24
+ # import urllib.parse
25
 
26
+ # - **Download SD 1.5 Models**
27
+ download_model = "https://civitai.com/api/download/models/574369, https://huggingface.co/TechnoByte/MilkyWonderland/resolve/main/milkyWonderland_v40.safetensors"
28
+ # - **Download VAEs**
29
+ download_vae = "https://huggingface.co/nubby/blessed-sdxl-vae-fp16-fix/resolve/main/sdxl_vae-fp16fix-c-1.1-b-0.5.safetensors?download=true, https://huggingface.co/nubby/blessed-sdxl-vae-fp16-fix/resolve/main/sdxl_vae-fp16fix-blessed.safetensors?download=true, https://huggingface.co/digiplay/VAE/resolve/main/vividReal_v20.safetensors?download=true, https://huggingface.co/fp16-guy/anything_kl-f8-anime2_vae-ft-mse-840000-ema-pruned_blessed_clearvae_fp16_cleaned/resolve/main/vae-ft-mse-840000-ema-pruned_fp16.safetensors?download=true"
30
+ # - **Download LoRAs**
31
+ download_lora = "https://civitai.com/api/download/models/28907, https://huggingface.co/Leopain/color/resolve/main/Coloring_book_-_LineArt.safetensors, https://civitai.com/api/download/models/135867, https://civitai.com/api/download/models/145907, https://huggingface.co/Linaqruf/anime-detailer-xl-lora/resolve/main/anime-detailer-xl.safetensors?download=true, https://huggingface.co/Linaqruf/style-enhancer-xl-lora/resolve/main/style-enhancer-xl.safetensors?download=true, https://civitai.com/api/download/models/28609, https://huggingface.co/ByteDance/Hyper-SD/resolve/main/Hyper-SD15-8steps-CFG-lora.safetensors?download=true, https://huggingface.co/ByteDance/Hyper-SD/resolve/main/Hyper-SDXL-8steps-CFG-lora.safetensors?download=true"
32
+ load_diffusers_format_model = [
33
+ 'stabilityai/stable-diffusion-xl-base-1.0',
34
+ 'black-forest-labs/FLUX.1-dev',
35
+ 'John6666/blue-pencil-flux1-v021-fp8-flux',
36
+ 'John6666/wai-ani-flux-v10forfp8-fp8-flux',
37
+ 'John6666/xe-anime-flux-v04-fp8-flux',
38
+ 'cagliostrolab/animagine-xl-3.1',
39
+ 'John6666/epicrealism-xl-v8kiss-sdxl',
40
+ 'misri/epicrealismXL_v7FinalDestination',
41
+ 'misri/juggernautXL_juggernautX',
42
+ 'misri/zavychromaxl_v80',
43
+ 'SG161222/RealVisXL_V4.0',
44
+ 'SG161222/RealVisXL_V5.0',
45
+ 'misri/newrealityxlAllInOne_Newreality40',
46
+ 'eienmojiki/Anything-XL',
47
+ 'eienmojiki/Starry-XL-v5.2',
48
+ 'gsdf/CounterfeitXL',
49
+ 'KBlueLeaf/Kohaku-XL-Zeta',
50
+ 'John6666/silvermoon-mix-01xl-v11-sdxl',
51
+ 'WhiteAiZ/autismmixSDXL_autismmixConfetti_diffusers',
52
+ 'kitty7779/ponyDiffusionV6XL',
53
+ 'GraydientPlatformAPI/aniverse-pony',
54
+ 'John6666/mistoon-anime-ponyalpha-sdxl',
55
+ 'John6666/ebara-mfcg-pony-mix-v12-sdxl',
56
+ 'John6666/t-ponynai3-v51-sdxl',
57
+ 'John6666/mala-anime-mix-nsfw-pony-xl-v5-sdxl',
58
+ 'John6666/wai-real-mix-v11-sdxl',
59
+ 'John6666/cyberrealistic-pony-v63-sdxl',
60
+ 'GraydientPlatformAPI/realcartoon-pony-diffusion',
61
+ 'John6666/nova-anime-xl-pony-v5-sdxl',
62
+ 'John6666/autismmix-sdxl-autismmix-pony-sdxl',
63
+ 'yodayo-ai/kivotos-xl-2.0',
64
+ 'yodayo-ai/holodayo-xl-2.1',
65
+ 'yodayo-ai/clandestine-xl-1.0',
66
+ 'digiplay/majicMIX_sombre_v2',
67
+ 'digiplay/majicMIX_realistic_v6',
68
+ 'digiplay/majicMIX_realistic_v7',
69
+ 'digiplay/DreamShaper_8',
70
+ 'digiplay/BeautifulArt_v1',
71
+ 'digiplay/DarkSushi2.5D_v1',
72
+ 'digiplay/darkphoenix3D_v1.1',
73
+ 'digiplay/BeenYouLiteL11_diffusers',
74
+ 'Yntec/RevAnimatedV2Rebirth',
75
+ 'youknownothing/cyberrealistic_v50',
76
+ 'youknownothing/deliberate-v6',
77
+ 'GraydientPlatformAPI/deliberate-cyber3',
78
+ 'GraydientPlatformAPI/picx-real',
79
+ 'GraydientPlatformAPI/perfectworld6',
80
+ 'emilianJR/epiCRealism',
81
+ 'votepurchase/counterfeitV30_v30',
82
+ 'votepurchase/ChilloutMix',
83
+ 'Meina/MeinaMix_V11',
84
+ 'Meina/MeinaUnreal_V5',
85
+ 'Meina/MeinaPastel_V7',
86
+ 'GraydientPlatformAPI/realcartoon3d-17',
87
+ 'GraydientPlatformAPI/realcartoon-pixar11',
88
+ 'GraydientPlatformAPI/realcartoon-real17',
89
+ ]
90
+
91
+ CIVITAI_API_KEY = os.environ.get("CIVITAI_API_KEY")
92
+ HF_TOKEN = os.environ.get("HF_READ_TOKEN")
93
+
94
+ PREPROCESSOR_CONTROLNET = {
95
  "openpose": [
96
  "Openpose",
97
  "None",
 
164
 
165
  }
166
 
167
+ TASK_STABLEPY = {
168
  'txt2img': 'txt2img',
169
  'img2img': 'img2img',
170
  'inpaint': 'inpaint',
 
190
  'tile ControlNet': 'tile',
191
  }
192
 
193
+ TASK_MODEL_LIST = list(TASK_STABLEPY.keys())
194
+
195
+ UPSCALER_DICT_GUI = {
196
+ None: None,
197
+ "Lanczos": "Lanczos",
198
+ "Nearest": "Nearest",
199
+ 'Latent': 'Latent',
200
+ 'Latent (antialiased)': 'Latent (antialiased)',
201
+ 'Latent (bicubic)': 'Latent (bicubic)',
202
+ 'Latent (bicubic antialiased)': 'Latent (bicubic antialiased)',
203
+ 'Latent (nearest)': 'Latent (nearest)',
204
+ 'Latent (nearest-exact)': 'Latent (nearest-exact)',
205
+ "RealESRGAN_x4plus": "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth",
206
+ "RealESRNet_x4plus": "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.1/RealESRNet_x4plus.pth",
207
+ "RealESRGAN_x4plus_anime_6B": "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth",
208
+ "RealESRGAN_x2plus": "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.1/RealESRGAN_x2plus.pth",
209
+ "realesr-animevideov3": "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-animevideov3.pth",
210
+ "realesr-general-x4v3": "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-general-x4v3.pth",
211
+ "realesr-general-wdn-x4v3": "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-general-wdn-x4v3.pth",
212
+ "4x-UltraSharp": "https://huggingface.co/Shandypur/ESRGAN-4x-UltraSharp/resolve/main/4x-UltraSharp.pth",
213
+ "4x_foolhardy_Remacri": "https://huggingface.co/FacehugmanIII/4x_foolhardy_Remacri/resolve/main/4x_foolhardy_Remacri.pth",
214
+ "Remacri4xExtraSmoother": "https://huggingface.co/hollowstrawberry/upscalers-backup/resolve/main/ESRGAN/Remacri%204x%20ExtraSmoother.pth",
215
+ "AnimeSharp4x": "https://huggingface.co/hollowstrawberry/upscalers-backup/resolve/main/ESRGAN/AnimeSharp%204x.pth",
216
+ "lollypop": "https://huggingface.co/hollowstrawberry/upscalers-backup/resolve/main/ESRGAN/lollypop.pth",
217
+ "RealisticRescaler4x": "https://huggingface.co/hollowstrawberry/upscalers-backup/resolve/main/ESRGAN/RealisticRescaler%204x.pth",
218
+ "NickelbackFS4x": "https://huggingface.co/hollowstrawberry/upscalers-backup/resolve/main/ESRGAN/NickelbackFS%204x.pth"
219
+ }
220
+
221
+ UPSCALER_KEYS = list(UPSCALER_DICT_GUI.keys())
222
 
223
 
224
  def download_things(directory, url, hf_token="", civitai_api_key=""):
 
257
 
258
  for filename in os.listdir(directory_path):
259
  if os.path.splitext(filename)[1] in valid_extensions:
260
+ # name_without_extension = os.path.splitext(filename)[0]
261
  file_path = os.path.join(directory_path, filename)
262
  # model_list.append((name_without_extension, file_path))
263
  model_list.append(file_path)
 
272
  directory_vaes = 'vaes'
273
  os.makedirs(directory_vaes, exist_ok=True)
274
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
275
  # Download stuffs
276
  for url in [url.strip() for url in download_model.split(',')]:
277
  if not os.path.exists(f"./models/{url.split('/')[-1]}"):
278
+ download_things(directory_models, url, HF_TOKEN, CIVITAI_API_KEY)
279
  for url in [url.strip() for url in download_vae.split(',')]:
280
  if not os.path.exists(f"./vaes/{url.split('/')[-1]}"):
281
+ download_things(directory_vaes, url, HF_TOKEN, CIVITAI_API_KEY)
282
  for url in [url.strip() for url in download_lora.split(',')]:
283
  if not os.path.exists(f"./loras/{url.split('/')[-1]}"):
284
+ download_things(directory_loras, url, HF_TOKEN, CIVITAI_API_KEY)
285
 
286
  # Download Embeddings
287
  directory_embeds = 'embedings'
 
294
 
295
  for url_embed in download_embeds:
296
  if not os.path.exists(f"./embedings/{url_embed.split('/')[-1]}"):
297
+ download_things(directory_embeds, url_embed, HF_TOKEN, CIVITAI_API_KEY)
298
 
299
  # Build list models
300
  embed_list = get_model_list(directory_embeds)
 
305
  vae_model_list = get_model_list(directory_vaes)
306
  vae_model_list.insert(0, "None")
307
 
308
+ print('\033[33m🏁 Download and listing of valid models completed.\033[0m')
309
 
310
+ #######################
311
+ # GUI
312
+ #######################
313
+ import gradio as gr
314
+ import logging
315
+ logging.getLogger("diffusers").setLevel(logging.ERROR)
316
+ import diffusers
317
+ diffusers.utils.logging.set_verbosity(40)
318
+ import warnings
319
+ warnings.filterwarnings(action="ignore", category=FutureWarning, module="diffusers")
320
+ warnings.filterwarnings(action="ignore", category=UserWarning, module="diffusers")
321
+ warnings.filterwarnings(action="ignore", category=FutureWarning, module="transformers")
322
+ from stablepy import logger
323
 
324
+ logger.setLevel(logging.DEBUG)
 
 
 
 
 
 
 
 
 
 
325
 
326
+ msg_inc_vae = (
327
+ "Use the right VAE for your model to maintain image quality. The wrong"
328
+ " VAE can lead to poor results, like blurriness in the generated images."
329
+ )
330
 
331
+ SDXL_TASK = [k for k, v in TASK_STABLEPY.items() if v in SDXL_TASKS]
332
+ SD_TASK = [k for k, v in TASK_STABLEPY.items() if v in SD15_TASKS]
333
+ FLUX_TASK = list(TASK_STABLEPY.keys())[:3] + [k for k, v in TASK_STABLEPY.items() if v in FLUX_CN_UNION_MODES.keys()]
334
 
335
+ MODEL_TYPE_TASK = {
336
+ "SD 1.5": SD_TASK,
337
+ "SDXL": SDXL_TASK,
338
+ "FLUX": FLUX_TASK,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
339
  }
340
 
341
+ MODEL_TYPE_CLASS = {
342
+ "diffusers:StableDiffusionPipeline": "SD 1.5",
343
+ "diffusers:StableDiffusionXLPipeline": "SDXL",
344
+ "diffusers:FluxPipeline": "FLUX",
345
+ }
346
+
347
+ POST_PROCESSING_SAMPLER = ["Use same sampler"] + scheduler_names[:-2]
348
+
349
+ CSS = """
350
+ .contain { display: flex; flex-direction: column; }
351
+ #component-0 { height: 100%; }
352
+ #gallery { flex-grow: 1; }
353
+ """
354
+
355
+ SUBTITLE_GUI = (
356
+ "### This demo uses [diffusers](https://github.com/huggingface/diffusers)"
357
+ " to perform different tasks in image generation."
358
+ )
359
 
360
 
361
  def extract_parameters(input_string):
362
  parameters = {}
363
  input_string = input_string.replace("\n", "")
364
 
365
+ if "Negative prompt:" not in input_string:
366
  print("Negative prompt not detected")
367
  parameters["prompt"] = input_string
368
  return parameters
369
 
370
  parm = input_string.split("Negative prompt:")
371
  parameters["prompt"] = parm[0]
372
+ if "Steps:" not in parm[1]:
373
  print("Steps not detected")
374
  parameters["neg_prompt"] = parm[1]
375
  return parameters
 
398
  return parameters
399
 
400
 
401
+ def get_my_lora(link_url):
402
+ for url in [url.strip() for url in link_url.split(',')]:
403
+ if not os.path.exists(f"./loras/{url.split('/')[-1]}"):
404
+ download_things(directory_loras, url, HF_TOKEN, CIVITAI_API_KEY)
405
+ new_lora_model_list = get_model_list(directory_loras)
406
+ new_lora_model_list.insert(0, "None")
 
 
 
 
 
 
 
 
 
 
407
 
408
+ return gr.update(
409
+ choices=new_lora_model_list
410
+ ), gr.update(
411
+ choices=new_lora_model_list
412
+ ), gr.update(
413
+ choices=new_lora_model_list
414
+ ), gr.update(
415
+ choices=new_lora_model_list
416
+ ), gr.update(
417
+ choices=new_lora_model_list
418
+ ),
419
 
420
 
421
  def info_html(json_data, title, subtitle):
 
465
  model_type = get_model_type(model_name)
466
 
467
  if vae_model:
468
+ vae_type = "SDXL" if "sdxl" in vae_model.lower() else "SD 1.5"
469
  if model_type != vae_type:
470
  gr.Info(msg_inc_vae)
471
 
 
474
 
475
  self.model.load_pipe(
476
  model_name,
477
+ task_name=TASK_STABLEPY[task],
478
  vae_model=vae_model,
479
  type_model_precision=dtype_model,
480
  retain_task_model_in_cache=False,
481
  )
482
+
483
  yield f"Model loaded: {model_name}"
484
 
485
  @spaces.GPU(duration=59)
 
597
 
598
  print("Config model:", model_name, vae_model, loras_list)
599
 
600
+ task = TASK_STABLEPY[task]
601
 
602
  params_ip_img = []
603
  params_ip_msk = []
 
627
  if task == "inpaint" and not image_mask:
628
  raise ValueError("No mask image found: Specify one in 'Image Mask'")
629
 
630
+ if upscaler_model_path in UPSCALER_KEYS[:9]:
631
  upscaler_model = upscaler_model_path
632
  else:
633
  directory_upscalers = 'upscalers'
634
  os.makedirs(directory_upscalers, exist_ok=True)
635
 
636
+ url_upscaler = UPSCALER_DICT_GUI[upscaler_model_path]
637
 
638
  if not os.path.exists(f"./upscalers/{url_upscaler.split('/')[-1]}"):
639
+ download_things(directory_upscalers, url_upscaler, HF_TOKEN)
640
 
641
  upscaler_model = f"./upscalers/{url_upscaler.split('/')[-1]}"
642
 
 
776
  yield img, info_state
777
 
778
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
779
  def update_task_options(model_name, task_name):
780
  new_choices = MODEL_TYPE_TASK[get_model_type(model_name)]
781
 
 
785
  return gr.update(value=task_name, choices=new_choices)
786
 
787
 
788
+ # def sd_gen_generate_pipeline(*args):
789
 
790
+ # # Load lora in CPU
791
+ # status_lora = sd_gen.model.lora_merge(
792
+ # lora_A=args[7] if args[7] != "None" else None, lora_scale_A=args[8],
793
+ # lora_B=args[9] if args[9] != "None" else None, lora_scale_B=args[10],
794
+ # lora_C=args[11] if args[11] != "None" else None, lora_scale_C=args[12],
795
+ # lora_D=args[13] if args[13] != "None" else None, lora_scale_D=args[14],
796
+ # lora_E=args[15] if args[15] != "None" else None, lora_scale_E=args[16],
797
+ # )
798
+
799
+ # lora_list = [args[7], args[9], args[11], args[13], args[15]]
800
+ # print(status_lora)
801
+ # for status, lora in zip(status_lora, lora_list):
802
+ # if status:
803
+ # gr.Info(f"LoRA loaded: {lora}")
804
+ # elif status is not None:
805
+ # gr.Warning(f"Failed to load LoRA: {lora}")
806
+
807
+ # # if status_lora == [None] * 5 and self.model.lora_memory != [None] * 5:
808
+ # # gr.Info(f"LoRAs in cache: {", ".join(str(x) for x in self.model.lora_memory if x is not None)}")
809
+
810
+ # yield from sd_gen.generate_pipeline(*args)
811
+
812
+
813
+ # sd_gen_generate_pipeline.zerogpu = True
814
+ sd_gen = GuiSD()
815
 
816
  with gr.Blocks(theme="NoCrypt/miku", css=CSS) as app:
817
  gr.Markdown("# 🧩 DiffuseCraft")
 
877
  "height": gr.update(value=1024),
878
  "Seed": gr.update(value=-1),
879
  "Sampler": gr.update(value="Euler a"),
880
+ "scale": gr.update(value=7.5), # cfg
881
  "skip": gr.update(value=True),
882
  }
883
  valid_keys = list(valid_receptors.keys())
 
887
  # print(val)
888
  if key in valid_keys:
889
  if key == "Sampler":
890
+ if val not in scheduler_names:
891
+ continue
892
  elif key == "skip":
893
+ if int(val) >= 2:
894
+ val = True
895
  if key == "prompt":
896
+ if ">" in val and "<" in val:
897
+ val = re.sub(r'<[^>]+>', '', val)
898
+ print("Removed LoRA written in the prompt")
899
  if key in ["prompt", "neg_prompt"]:
900
  val = val.strip()
901
  if key in ["Steps", "width", "height", "Seed"]:
 
910
  return [value for value in valid_receptors.values()]
911
 
912
  set_params_gui.click(
913
+ run_set_params_gui, [prompt_gui], [
914
  prompt_gui,
915
  neg_prompt_gui,
916
  steps_gui,
 
949
 
950
  with gr.Accordion("Hires fix", open=False, visible=True):
951
 
952
+ upscaler_model_path_gui = gr.Dropdown(label="Upscaler", choices=UPSCALER_KEYS, value=UPSCALER_KEYS[0])
953
  upscaler_increases_size_gui = gr.Slider(minimum=1.1, maximum=6., step=0.1, value=1.4, label="Upscale by")
954
  esrgan_tile_gui = gr.Slider(minimum=0, value=100, maximum=500, step=1, label="ESRGAN Tile")
955
  esrgan_tile_overlap_gui = gr.Slider(minimum=1, maximum=200, step=1, value=10, label="ESRGAN Tile Overlap")
 
1013
  info="This option adjusts the level of changes for img2img and inpainting."
1014
  )
1015
  image_resolution_gui = gr.Slider(minimum=64, maximum=2048, step=64, value=1024, label="Image Resolution")
1016
+ preprocessor_name_gui = gr.Dropdown(label="Preprocessor Name", choices=PREPROCESSOR_CONTROLNET["canny"])
1017
 
1018
  def change_preprocessor_choices(task):
1019
+ task = TASK_STABLEPY[task]
1020
+ if task in PREPROCESSOR_CONTROLNET.keys():
1021
+ choices_task = PREPROCESSOR_CONTROLNET[task]
1022
  else:
1023
+ choices_task = PREPROCESSOR_CONTROLNET["canny"]
1024
  return gr.update(choices=choices_task, value=choices_task[0])
1025
 
1026
  task_gui.change(
 
1046
 
1047
  try:
1048
  style_names_found = sd_gen.model.STYLE_NAMES
1049
+ except Exception:
1050
  style_names_found = STYLE_NAMES
1051
 
1052
  style_prompt_gui = gr.Dropdown(
 
1144
  3. ControlNet Canny SDXL
1145
  4. Optical pattern (Optical illusion) SDXL
1146
  5. Convert an image to a coloring drawing
1147
+ 6. ControlNet OpenPose SD 1.5 and Latent upscale
1148
 
1149
  - Different tasks can be performed, such as img2img or using the IP adapter, to preserve a person's appearance or a specific style based on an image.
1150
  """
 
1152
  gr.Examples(
1153
  examples=[
1154
  [
1155
+ "1girl, souryuu asuka langley, neon genesis evangelion, rebuild of evangelion, lance of longinus, cat hat, plugsuit, pilot suit, red bodysuit, sitting, crossed legs, black eye patch, throne, looking down, from bottom, looking at viewer, outdoors, (masterpiece), (best quality), (ultra-detailed), very aesthetic, illustration, disheveled hair, perfect composition, moist skin, intricate details",
1156
+ "nfsw, lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, unfinished, very displeasing, oldest, early, chromatic aberration, artistic error, scan, abstract",
1157
+ 28,
1158
+ 7.0,
 
 
1159
  -1,
1160
  "None",
1161
+ 0.33,
 
 
 
 
 
 
 
 
1162
  "Euler a",
1163
  1152,
1164
  896,
1165
  "cagliostrolab/animagine-xl-3.1",
 
1166
  "txt2img",
1167
+ "image.webp", # img conttol
1168
+ 1024, # img resolution
1169
+ 0.35, # strength
1170
+ 1.0, # cn scale
1171
+ 0.0, # cn start
1172
+ 1.0, # cn end
 
 
 
 
 
 
 
 
 
 
1173
  "Classic",
1174
  "Nearest",
1175
  ],
1176
  [
1177
+ "a digital illustration of a movie poster titled 'Finding Emo', finding nemo parody poster, featuring a depressed cartoon clownfish with black emo hair, eyeliner, and piercings, bored expression, swimming in a dark underwater scene, in the background, movie title in a dripping, grungy font, moody blue and purple color palette",
1178
  "",
1179
+ 25,
 
1180
  3.5,
 
1181
  -1,
1182
  "None",
1183
+ 0.33,
 
 
 
 
 
 
 
 
1184
  "Euler a",
1185
+ 1152,
1186
+ 896,
1187
  "black-forest-labs/FLUX.1-dev",
 
1188
  "txt2img",
1189
+ None, # img conttol
1190
+ 1024, # img resolution
1191
+ 0.35, # strength
1192
+ 1.0, # cn scale
1193
+ 0.0, # cn start
1194
+ 1.0, # cn end
 
 
 
 
 
 
 
 
 
 
1195
  "Classic",
1196
  None,
1197
  ],
1198
  [
1199
+ "((masterpiece)), best quality, blonde disco girl, detailed face, realistic face, realistic hair, dynamic pose, pink pvc, intergalactic disco background, pastel lights, dynamic contrast, airbrush, fine detail, 70s vibe, midriff",
1200
  "(worst quality:1.2), (bad quality:1.2), (poor quality:1.2), (missing fingers:1.2), bad-artist-anime, bad-artist, bad-picture-chill-75v",
 
1201
  48,
1202
  3.5,
 
1203
  -1,
1204
  "None",
1205
+ 0.33,
 
 
 
 
 
 
 
 
1206
  "DPM++ 2M SDE Lu",
1207
  1024,
1208
  1024,
1209
  "misri/epicrealismXL_v7FinalDestination",
 
1210
  "canny ControlNet",
1211
+ "image.webp", # img conttol
1212
+ 1024, # img resolution
1213
+ 0.35, # strength
1214
+ 1.0, # cn scale
1215
+ 0.0, # cn start
1216
+ 1.0, # cn end
 
 
 
 
 
 
 
 
 
 
1217
  "Classic",
1218
  None,
1219
  ],
1220
  [
1221
  "cinematic scenery old city ruins",
1222
  "(worst quality, low quality, illustration, 3d, 2d, painting, cartoons, sketch), (illustration, 3d, 2d, painting, cartoons, sketch, blurry, film grain, noise), (low quality, worst quality:1.2)",
 
1223
  50,
1224
+ 4.0,
 
1225
  -1,
1226
  "None",
1227
+ 0.33,
 
 
 
 
 
 
 
 
1228
  "Euler a",
1229
  1024,
1230
  1024,
1231
  "misri/juggernautXL_juggernautX",
 
1232
  "optical pattern ControlNet",
1233
+ "spiral_no_transparent.png", # img conttol
1234
+ 1024, # img resolution
1235
+ 0.35, # strength
1236
+ 1.0, # cn scale
1237
+ 0.05, # cn start
1238
+ 0.75, # cn end
 
 
 
 
 
 
 
 
 
 
1239
  "Classic",
1240
  None,
1241
  ],
1242
  [
1243
  "black and white, line art, coloring drawing, clean line art, black strokes, no background, white, black, free lines, black scribbles, on paper, A blend of comic book art and lineart full of black and white color, masterpiece, high-resolution, trending on Pixiv fan box, palette knife, brush strokes, two-dimensional, planar vector, T-shirt design, stickers, and T-shirt design, vector art, fantasy art, Adobe Illustrator, hand-painted, digital painting, low polygon, soft lighting, aerial view, isometric style, retro aesthetics, 8K resolution, black sketch lines, monochrome, invert color",
1244
  "color, red, green, yellow, colored, duplicate, blurry, abstract, disfigured, deformed, animated, toy, figure, framed, 3d, bad art, poorly drawn, extra limbs, close up, b&w, weird colors, blurry, watermark, blur haze, 2 heads, long neck, watermark, elongated body, cropped image, out of frame, draft, deformed hands, twisted fingers, double image, malformed hands, multiple heads, extra limb, ugly, poorly drawn hands, missing limb, cut-off, over satured, grain, lowères, bad anatomy, poorly drawn face, mutation, mutated, floating limbs, disconnected limbs, out of focus, long body, disgusting, extra fingers, groos proportions, missing arms, mutated hands, cloned face, missing legs, ugly, tiling, poorly drawn hands, poorly drawn feet, poorly drawn face, out of frame, extra limbs, disfigured, deformed, body out of frame, blurry, bad anatomy, blurred, watermark, grainy, signature, cut off, draft, deformed, blurry, bad anatomy, disfigured, poorly drawn face, mutation, bluelish, blue",
 
1245
  20,
1246
+ 4.0,
 
1247
  -1,
1248
  "loras/Coloring_book_-_LineArt.safetensors",
1249
  1.0,
 
 
 
 
 
 
 
 
1250
  "DPM++ 2M SDE Karras",
1251
  1024,
1252
  1024,
1253
  "cagliostrolab/animagine-xl-3.1",
 
1254
  "lineart ControlNet",
1255
+ "color_image.png", # img conttol
1256
+ 896, # img resolution
1257
+ 0.35, # strength
1258
+ 1.0, # cn scale
1259
+ 0.0, # cn start
1260
+ 1.0, # cn end
 
 
 
 
 
 
 
 
 
 
1261
  "Compel",
1262
  None,
1263
  ],
1264
  [
1265
  "1girl,face,curly hair,red hair,white background,",
1266
  "(worst quality:2),(low quality:2),(normal quality:2),lowres,watermark,",
 
1267
  38,
1268
+ 5.0,
 
1269
  -1,
1270
  "None",
1271
+ 0.33,
 
 
 
 
 
 
 
 
1272
  "DPM++ 2M SDE Karras",
1273
  512,
1274
  512,
1275
  "digiplay/majicMIX_realistic_v7",
 
1276
  "openpose ControlNet",
1277
+ "image.webp", # img conttol
1278
+ 1024, # img resolution
1279
+ 0.35, # strength
1280
+ 1.0, # cn scale
1281
+ 0.0, # cn start
1282
+ 0.9, # cn end
 
 
 
 
 
 
 
 
 
 
1283
  "Compel",
1284
+ "Latent (antialiased)",
1285
  ],
1286
  ],
1287
  fn=sd_gen.generate_pipeline,
1288
  inputs=[
1289
  prompt_gui,
1290
  neg_prompt_gui,
 
1291
  steps_gui,
1292
  cfg_gui,
 
1293
  seed_gui,
1294
  lora1_gui,
1295
  lora_scale_1_gui,
 
 
 
 
 
 
 
 
1296
  sampler_gui,
1297
  img_height_gui,
1298
  img_width_gui,
1299
  model_name_gui,
 
1300
  task_gui,
1301
  image_control,
 
 
1302
  image_resolution_gui,
 
 
 
1303
  strength_gui,
 
 
 
 
1304
  control_net_output_scaling_gui,
1305
  control_net_start_threshold_gui,
1306
  control_net_stop_threshold_gui,
 
1307
  prompt_syntax_gui,
1308
  upscaler_model_path_gui,
1309
  ],
1310
+ outputs=[result_images, actual_task_info],
1311
  cache_examples=False,
1312
  )
1313
 
 
1349
  # enable crop (or disable it)
1350
  # transforms=["crop"],
1351
  brush=gr.Brush(
1352
+ default_size="16", # or leave it as 'auto'
1353
+ color_mode="fixed", # 'fixed' hides the user swatches and colorpicker, 'defaults' shows it
1354
  # default_color="black", # html names are supported
1355
  colors=[
1356
+ "rgba(0, 0, 0, 1)", # rgb(a)
1357
  "rgba(0, 0, 0, 0.1)",
1358
  "rgba(255, 255, 255, 0.1)",
1359
  # "hsl(360, 120, 120)" # in fact any valid colorstring
 
1385
  queue=True,
1386
  show_progress="minimal",
1387
  ).success(
1388
+ fn=sd_gen.generate_pipeline, # fn=sd_gen_generate_pipeline,
1389
  inputs=[
1390
  prompt_gui,
1391
  neg_prompt_gui,