John6666 commited on
Commit
c2d516c
1 Parent(s): c0ce642

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +39 -73
  2. modutils.py +235 -0
app.py CHANGED
@@ -169,6 +169,12 @@ os.makedirs(directory_vaes, exist_ok=True)
169
 
170
 
171
  ## BEGIN MOD
 
 
 
 
 
 
172
  # - **Download SD 1.5 Models**
173
  #download_model = "https://huggingface.co/frankjoshua/toonyou_beta6/resolve/main/toonyou_beta6.safetensors"
174
  download_model = ""
@@ -183,35 +189,9 @@ download_vae = ", ".join(download_vae_list)
183
  download_lora_list = []
184
  download_lora = ", ".join(download_lora_list)
185
 
186
- def download_private_repo(repo_id, dir_path):
187
- from huggingface_hub import snapshot_download
188
- snapshot_download(repo_id=repo_id, local_dir=dir_path, allow_patterns=["*.safetensors"], use_auth_token=os.environ['HF_READ_TOKEN'])
189
-
190
  download_private_repo('John6666/loratest', directory_loras)
191
  download_private_repo('John6666/vaetest', directory_vaes)
192
 
193
- def get_model_id_list():
194
- from huggingface_hub import HfApi
195
- api = HfApi()
196
- model_ids = []
197
-
198
- models_vp = api.list_models(author="votepurchase", cardData=True, sort="likes")
199
- models_john = api.list_models(author="John6666", cardData=True, sort="last_modified")
200
-
201
- for model in models_vp:
202
- model_ids.append(model.id) if not model.private else ""
203
-
204
- anime_models = []
205
- real_models = []
206
- for model in models_john:
207
- if not model.private:
208
- anime_models.append(model.id) if 'anime' in model.tags else real_models.append(model.id)
209
-
210
- model_ids.extend(anime_models)
211
- model_ids.extend(real_models)
212
-
213
- return model_ids
214
-
215
  load_diffusers_format_model = [
216
  'stabilityai/stable-diffusion-xl-base-1.0',
217
  'cagliostrolab/animagine-xl-3.1',
@@ -247,9 +227,6 @@ load_diffusers_format_model = [
247
  'Raelina/Rae-Diffusion-XL-V2',
248
  ]
249
 
250
- def list_uniq(l):
251
- return sorted(set(l), key=l.index)
252
-
253
  load_diffusers_format_model = list_uniq(get_model_id_list() + load_diffusers_format_model)
254
  ## END MOD
255
 
@@ -417,6 +394,13 @@ from tagger import (
417
  from fl2sd3longcap import (
418
  predict_tags_fl2_sd3,
419
  )
 
 
 
 
 
 
 
420
  def description_ui():
421
  gr.Markdown(
422
  """
@@ -816,11 +800,14 @@ class GuiSD:
816
 
817
  sd_gen = GuiSD()
818
 
 
819
  CSS ="""
820
  .contain { display: flex; flex-direction: column; }
821
  #component-0 { height: 100%; }
822
  #gallery { flex-grow: 1; }
823
  """
 
 
824
  sdxl_task = [k for k, v in task_stablepy.items() if v in SDXL_TASKS ]
825
  sd_task = [k for k, v in task_stablepy.items() if v in SD15_TASKS ]
826
  def update_task_options(model_name, task_name):
@@ -837,9 +824,10 @@ def update_task_options(model_name, task_name):
837
  else:
838
  return gr.update(value=task_name, choices=task_model_list)
839
 
840
-
841
  ## BEGIN MOD
842
  with gr.Blocks(theme="NoCrypt/miku", elem_id="main", css=CSS) as app:
 
 
843
  gr.Markdown("# 🧩 DiffuseCraft Mod")
844
  gr.Markdown(
845
  f"""
@@ -853,7 +841,9 @@ with gr.Blocks(theme="NoCrypt/miku", elem_id="main", css=CSS) as app:
853
  with gr.Accordion("Model and Task", open=False):
854
  task_gui = gr.Dropdown(label="Task", choices=sdxl_task, value=task_model_list[0])
855
  model_name_gui = gr.Dropdown(label="Model", choices=model_list, value="votepurchase/animagine-xl-3.1", allow_custom_value=True)
856
- optimization_gui = gr.Radio(label="Optimization for SDXL", choices=["None", "Default", "SPO", "DPO", "DPO Turbo", "Hyper-SDXL", "PCM 16step", "PCM 8step"], value="None", interactive=True)
 
 
857
  with gr.Accordion("Generate prompt from Image", open=False):
858
  input_image_gui = gr.Image(label="Input image", type="pil", sources=["upload", "clipboard"], height=256)
859
  with gr.Accordion(label="Advanced options", open=False):
@@ -915,7 +905,7 @@ with gr.Blocks(theme="NoCrypt/miku", elem_id="main", css=CSS) as app:
915
  format="png",
916
  )
917
 
918
- result_images_files = gr.Files(interactive=False)
919
 
920
  actual_task_info = gr.HTML()
921
 
@@ -1016,7 +1006,7 @@ with gr.Blocks(theme="NoCrypt/miku", elem_id="main", css=CSS) as app:
1016
  upscaler_keys = list(upscaler_dict_gui.keys())
1017
 
1018
  upscaler_model_path_gui = gr.Dropdown(label="Upscaler", choices=upscaler_keys, value=None)
1019
- upscaler_increases_size_gui = gr.Slider(minimum=1.1, maximum=6., step=0.1, value=1.4, label="Upscale by")
1020
  esrgan_tile_gui = gr.Slider(minimum=0, value=100, maximum=500, step=1, label="ESRGAN Tile")
1021
  esrgan_tile_overlap_gui = gr.Slider(minimum=1, maximum=200, step=1, value=10, label="ESRGAN Tile Overlap")
1022
  hires_steps_gui = gr.Slider(minimum=0, value=30, maximum=100, step=1, label="Hires Steps")
@@ -1412,6 +1402,7 @@ with gr.Blocks(theme="NoCrypt/miku", elem_id="main", css=CSS) as app:
1412
  ],
1413
  outputs=[result_images],
1414
  cache_examples=False,
 
1415
  )
1416
  ## END MOD
1417
 
@@ -1479,45 +1470,8 @@ with gr.Blocks(theme="NoCrypt/miku", elem_id="main", css=CSS) as app:
1479
  btn_send.click(send_img, [img_source, img_result], [image_control, image_mask_gui])
1480
 
1481
  ## BEGIN MOD
1482
- def set_optimization(opt, steps_gui, cfg_gui, sampler_gui, clip_skip_gui, lora1_gui, lora_scale_1_gui):
1483
- if opt == 'SPO':
1484
- return 28, 7., 'Euler a', True, 'loras/spo_sdxl_10ep_4k-data_lora_diffusers.safetensors', 1.
1485
- elif opt == 'PCM 16step':
1486
- return 16, 6., 'Euler a trailing', True, 'loras/pcm_sdxl_normalcfg_16step_converted.safetensors', 1.
1487
- elif opt == 'PCM 8step':
1488
- return 8, 6., 'Euler a trailing', True, 'loras/pcm_sdxl_normalcfg_8step_converted.safetensors', 1.
1489
- elif opt == 'DPO':
1490
- return 28, 7., 'Euler', True, 'loras/sdxl-DPO-LoRA.safetensors', 1.
1491
- elif opt == 'DPO Turbo':
1492
- return 8, 2.5, 'LCM', True, 'loras/sd_xl_dpo_turbo_lora_v1-128dim.safetensors', 1.
1493
- elif opt == 'Hyper-SDXL':
1494
- return 12, 6., 'Euler', True, 'loras/Hyper-SDXL-12steps-CFG-lora.safetensors', 0.9
1495
- elif opt == 'Default':
1496
- return 28, 7., 'Euler a', False, None, 1.
1497
- else: # None
1498
- return steps_gui, cfg_gui, sampler_gui, clip_skip_gui, lora1_gui, lora_scale_1_gui
1499
-
1500
  optimization_gui.change(set_optimization, [optimization_gui, steps_gui, cfg_gui, sampler_gui, clip_skip_gui, lora1_gui, lora_scale_1_gui], [steps_gui, cfg_gui, sampler_gui, clip_skip_gui, lora1_gui, lora_scale_1_gui])
1501
 
1502
- def save_gallery_images(images):
1503
- from datetime import datetime, timezone, timedelta
1504
- japan_tz = timezone(timedelta(hours=9))
1505
- dt_now = datetime.utcnow().replace(tzinfo=timezone.utc).astimezone(japan_tz)
1506
- basename = dt_now.strftime('%Y%m%d_%H%M%S_')
1507
- i = 1
1508
- if not images: return images
1509
- output_images = []
1510
- output_paths = []
1511
- for image in images:
1512
- from pathlib import Path
1513
- filename = basename + str(i) + ".png"
1514
- oldpath = Path(image[0])
1515
- newpath = oldpath.rename(Path(filename))
1516
- output_paths.append(str(newpath))
1517
- output_images.append((str(newpath), str(filename)))
1518
- i += 1
1519
- return output_images, output_paths
1520
-
1521
  generate_from_image_btn_gui.click(
1522
  predict_tags_wd,
1523
  inputs=[input_image_gui, prompt_gui, image_algorithms, general_threshold_gui, character_threshold_gui],
@@ -1554,8 +1508,20 @@ with gr.Blocks(theme="NoCrypt/miku", elem_id="main", css=CSS) as app:
1554
  ]
1555
 
1556
  insert_prompt_gui.change(
1557
- insert_recom_prompt,
1558
- inputs=[prompt_gui, neg_prompt_gui, insert_prompt_gui],
 
 
 
 
 
 
 
 
 
 
 
 
1559
  outputs=[prompt_gui, neg_prompt_gui],
1560
  )
1561
 
@@ -1695,7 +1661,7 @@ with gr.Blocks(theme="NoCrypt/miku", elem_id="main", css=CSS) as app:
1695
  outputs=[result_images, actual_task_info],
1696
  queue=True,
1697
  show_progress="minimal",
1698
- ).success(save_gallery_images, [result_images], [result_images, result_images_files])
1699
 
1700
  with gr.Tab("Danbooru Tags Transformer with WD Tagger", render=True):
1701
  v2 = V2UI()
 
169
 
170
 
171
  ## BEGIN MOD
172
+ from modutils import (
173
+ download_private_repo,
174
+ get_model_id_list,
175
+ list_uniq,
176
+ )
177
+
178
  # - **Download SD 1.5 Models**
179
  #download_model = "https://huggingface.co/frankjoshua/toonyou_beta6/resolve/main/toonyou_beta6.safetensors"
180
  download_model = ""
 
189
  download_lora_list = []
190
  download_lora = ", ".join(download_lora_list)
191
 
 
 
 
 
192
  download_private_repo('John6666/loratest', directory_loras)
193
  download_private_repo('John6666/vaetest', directory_vaes)
194
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
195
  load_diffusers_format_model = [
196
  'stabilityai/stable-diffusion-xl-base-1.0',
197
  'cagliostrolab/animagine-xl-3.1',
 
227
  'Raelina/Rae-Diffusion-XL-V2',
228
  ]
229
 
 
 
 
230
  load_diffusers_format_model = list_uniq(get_model_id_list() + load_diffusers_format_model)
231
  ## END MOD
232
 
 
394
  from fl2sd3longcap import (
395
  predict_tags_fl2_sd3,
396
  )
397
+ from modutils import (
398
+ save_gallery_images,
399
+ set_optimization,
400
+ process_style_prompt,
401
+ preset_styles,
402
+ preset_quality,
403
+ )
404
  def description_ui():
405
  gr.Markdown(
406
  """
 
800
 
801
  sd_gen = GuiSD()
802
 
803
+ ## BEGIN MOD
804
  CSS ="""
805
  .contain { display: flex; flex-direction: column; }
806
  #component-0 { height: 100%; }
807
  #gallery { flex-grow: 1; }
808
  """
809
+ ## END MOD
810
+
811
  sdxl_task = [k for k, v in task_stablepy.items() if v in SDXL_TASKS ]
812
  sd_task = [k for k, v in task_stablepy.items() if v in SD15_TASKS ]
813
  def update_task_options(model_name, task_name):
 
824
  else:
825
  return gr.update(value=task_name, choices=task_model_list)
826
 
 
827
  ## BEGIN MOD
828
  with gr.Blocks(theme="NoCrypt/miku", elem_id="main", css=CSS) as app:
829
+ allow_flagging="never"
830
+ title="DiffuseCraft Mod"
831
  gr.Markdown("# 🧩 DiffuseCraft Mod")
832
  gr.Markdown(
833
  f"""
 
841
  with gr.Accordion("Model and Task", open=False):
842
  task_gui = gr.Dropdown(label="Task", choices=sdxl_task, value=task_model_list[0])
843
  model_name_gui = gr.Dropdown(label="Model", choices=model_list, value="votepurchase/animagine-xl-3.1", allow_custom_value=True)
844
+ quality_selector_gui = gr.Dropdown(label="Quality Tags Presets", interactive=True, choices=list(preset_quality.keys()), value="None")
845
+ style_selector_gui = gr.Dropdown(label="Style Preset", interactive=True, choices=list(preset_styles.keys()), value="None")
846
+ optimization_gui = gr.Dropdown(label="Optimization for SDXL", choices=["None", "Default", "SPO", "DPO", "DPO Turbo", "Hyper-SDXL", "PCM 16step", "PCM 8step"], value="None", interactive=True)
847
  with gr.Accordion("Generate prompt from Image", open=False):
848
  input_image_gui = gr.Image(label="Input image", type="pil", sources=["upload", "clipboard"], height=256)
849
  with gr.Accordion(label="Advanced options", open=False):
 
905
  format="png",
906
  )
907
 
908
+ result_images_files = gr.Files(interactive=False, visible=False)
909
 
910
  actual_task_info = gr.HTML()
911
 
 
1006
  upscaler_keys = list(upscaler_dict_gui.keys())
1007
 
1008
  upscaler_model_path_gui = gr.Dropdown(label="Upscaler", choices=upscaler_keys, value=None)
1009
+ upscaler_increases_size_gui = gr.Slider(minimum=1.1, maximum=6., step=0.1, value=1.0, label="Upscale by")
1010
  esrgan_tile_gui = gr.Slider(minimum=0, value=100, maximum=500, step=1, label="ESRGAN Tile")
1011
  esrgan_tile_overlap_gui = gr.Slider(minimum=1, maximum=200, step=1, value=10, label="ESRGAN Tile Overlap")
1012
  hires_steps_gui = gr.Slider(minimum=0, value=30, maximum=100, step=1, label="Hires Steps")
 
1402
  ],
1403
  outputs=[result_images],
1404
  cache_examples=False,
1405
+ elem_id="examples",
1406
  )
1407
  ## END MOD
1408
 
 
1470
  btn_send.click(send_img, [img_source, img_result], [image_control, image_mask_gui])
1471
 
1472
  ## BEGIN MOD
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1473
  optimization_gui.change(set_optimization, [optimization_gui, steps_gui, cfg_gui, sampler_gui, clip_skip_gui, lora1_gui, lora_scale_1_gui], [steps_gui, cfg_gui, sampler_gui, clip_skip_gui, lora1_gui, lora_scale_1_gui])
1474
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1475
  generate_from_image_btn_gui.click(
1476
  predict_tags_wd,
1477
  inputs=[input_image_gui, prompt_gui, image_algorithms, general_threshold_gui, character_threshold_gui],
 
1508
  ]
1509
 
1510
  insert_prompt_gui.change(
1511
+ process_style_prompt,
1512
+ inputs=[prompt_gui, neg_prompt_gui, style_selector_gui, quality_selector_gui, insert_prompt_gui],
1513
+ outputs=[prompt_gui, neg_prompt_gui],
1514
+ )
1515
+
1516
+ quality_selector_gui.change(
1517
+ process_style_prompt,
1518
+ inputs=[prompt_gui, neg_prompt_gui, style_selector_gui, quality_selector_gui, insert_prompt_gui],
1519
+ outputs=[prompt_gui, neg_prompt_gui],
1520
+ )
1521
+
1522
+ style_selector_gui.change(
1523
+ process_style_prompt,
1524
+ inputs=[prompt_gui, neg_prompt_gui, style_selector_gui, quality_selector_gui, insert_prompt_gui],
1525
  outputs=[prompt_gui, neg_prompt_gui],
1526
  )
1527
 
 
1661
  outputs=[result_images, actual_task_info],
1662
  queue=True,
1663
  show_progress="minimal",
1664
+ ).success(save_gallery_images, [result_images], [result_images, result_images_files, result_images_files])
1665
 
1666
  with gr.Tab("Danbooru Tags Transformer with WD Tagger", render=True):
1667
  v2 = V2UI()
modutils.py ADDED
@@ -0,0 +1,235 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from PIL import Image
4
+
5
+
6
+ def list_uniq(l):
7
+ return sorted(set(l), key=l.index)
8
+
9
+
10
+ def download_private_repo(repo_id, dir_path):
11
+ from huggingface_hub import snapshot_download
12
+ hf_read_token = os.environ.get('HF_READ_TOKEN')
13
+ if not hf_read_token: return
14
+ snapshot_download(repo_id=repo_id, local_dir=dir_path, allow_patterns=["*.safetensors"], use_auth_token=hf_read_token)
15
+
16
+
17
+ def get_model_id_list():
18
+ from huggingface_hub import HfApi
19
+ api = HfApi()
20
+ model_ids = []
21
+
22
+ models_vp = api.list_models(author="votepurchase", cardData=True, sort="likes")
23
+ models_john = api.list_models(author="John6666", cardData=True, sort="last_modified")
24
+
25
+ for model in models_vp:
26
+ model_ids.append(model.id) if not model.private else ""
27
+
28
+ anime_models = []
29
+ real_models = []
30
+ for model in models_john:
31
+ if not model.private:
32
+ anime_models.append(model.id) if 'anime' in model.tags else real_models.append(model.id)
33
+
34
+ model_ids.extend(anime_models)
35
+ model_ids.extend(real_models)
36
+
37
+ return model_ids
38
+
39
+
40
+ def set_optimization(opt, steps_gui, cfg_gui, sampler_gui, clip_skip_gui, lora1_gui, lora_scale_1_gui):
41
+ def_steps_gui = 28
42
+ def_cfg_gui = 7.
43
+ if opt == 'SPO':
44
+ return max(steps_gui, def_steps_gui), max(cfg_gui, def_cfg_gui), 'Euler a', True, 'loras/spo_sdxl_10ep_4k-data_lora_diffusers.safetensors', 1.
45
+ elif opt == 'PCM 16step':
46
+ return 16, 6., 'Euler a trailing', True, 'loras/pcm_sdxl_normalcfg_16step_converted.safetensors', 1.
47
+ elif opt == 'PCM 8step':
48
+ return 8, 6., 'Euler a trailing', True, 'loras/pcm_sdxl_normalcfg_8step_converted.safetensors', 1.
49
+ elif opt == 'DPO':
50
+ return max(steps_gui, def_steps_gui), max(cfg_gui, def_cfg_gui), 'Euler', True, 'loras/sdxl-DPO-LoRA.safetensors', 1.
51
+ elif opt == 'DPO Turbo':
52
+ return 8, 2.5, 'LCM', True, 'loras/sd_xl_dpo_turbo_lora_v1-128dim.safetensors', 1.
53
+ elif opt == 'Hyper-SDXL':
54
+ return 12, 6., 'Euler', True, 'loras/Hyper-SDXL-12steps-CFG-lora.safetensors', 0.9
55
+ elif opt == 'Default':
56
+ return def_steps_gui, def_cfg_gui, 'Euler a', False, None, 1.
57
+ else: # None
58
+ return steps_gui, cfg_gui, sampler_gui, clip_skip_gui, lora1_gui, lora_scale_1_gui
59
+
60
+
61
+ def save_gallery_images(images):
62
+ from datetime import datetime, timezone, timedelta
63
+ japan_tz = timezone(timedelta(hours=9))
64
+ dt_now = datetime.utcnow().replace(tzinfo=timezone.utc).astimezone(japan_tz)
65
+ basename = dt_now.strftime('%Y%m%d_%H%M%S_')
66
+ i = 1
67
+ if not images: return images
68
+ output_images = []
69
+ output_paths = []
70
+ for image in images:
71
+ from pathlib import Path
72
+ filename = basename + str(i) + ".png"
73
+ oldpath = Path(image[0])
74
+ newpath = oldpath.rename(Path(filename))
75
+ output_paths.append(str(newpath))
76
+ output_images.append((str(newpath), str(filename)))
77
+ i += 1
78
+ return output_images, output_paths, gr.update(visible=True),
79
+
80
+
81
+ quality_prompt_list = [
82
+ {
83
+ "name": "None",
84
+ "prompt": "",
85
+ "negative_prompt": "lowres",
86
+ },
87
+ {
88
+ "name": "Animagine Common",
89
+ "prompt": "anime artwork, anime style, key visual, vibrant, studio anime, highly detailed, masterpiece, best quality, very aesthetic, absurdres",
90
+ "negative_prompt": "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]",
91
+ },
92
+ {
93
+ "name": "Pony Anime Models Common",
94
+ "prompt": "source_anime, score_9, score_8_up, score_7_up, masterpiece, best quality, very aesthetic, absurdres",
95
+ "negative_prompt": "source_pony, source_furry, source_cartoon, score_6, score_5, score_4, busty, ugly face, mutated hands, low res, blurry face, black and white, the simpsons, overwatch, apex legends",
96
+ },
97
+ {
98
+ "name": "Pony Common",
99
+ "prompt": "source_anime, score_9, score_8_up, score_7_up",
100
+ "negative_prompt": "source_pony, source_furry, source_cartoon, score_6, score_5, score_4, busty, ugly face, mutated hands, low res, blurry face, black and white, the simpsons, overwatch, apex legends",
101
+ },
102
+ {
103
+ "name": "Animagine Standard v3.0",
104
+ "prompt": "masterpiece, best quality",
105
+ "negative_prompt": "lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, artist name",
106
+ },
107
+ {
108
+ "name": "Animagine Standard v3.1",
109
+ "prompt": "masterpiece, best quality, very aesthetic, absurdres",
110
+ "negative_prompt": "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]",
111
+ },
112
+ {
113
+ "name": "Animagine Light v3.1",
114
+ "prompt": "(masterpiece), best quality, very aesthetic, perfect face",
115
+ "negative_prompt": "(low quality, worst quality:1.2), very displeasing, 3d, watermark, signature, ugly, poorly drawn",
116
+ },
117
+ {
118
+ "name": "Animagine Heavy v3.1",
119
+ "prompt": "(masterpiece), (best quality), (ultra-detailed), very aesthetic, illustration, disheveled hair, perfect composition, moist skin, intricate details",
120
+ "negative_prompt": "longbody, lowres, bad anatomy, bad hands, missing fingers, pubic hair, extra digit, fewer digits, cropped, worst quality, low quality, very displeasing",
121
+ },
122
+ ]
123
+
124
+ style_list = [
125
+ {
126
+ "name": "None",
127
+ "prompt": "",
128
+ "negative_prompt": "",
129
+ },
130
+ {
131
+ "name": "Cinematic",
132
+ "prompt": "cinematic still, emotional, harmonious, vignette, highly detailed, high budget, bokeh, cinemascope, moody, epic, gorgeous, film grain, grainy",
133
+ "negative_prompt": "cartoon, graphic, text, painting, crayon, graphite, abstract, glitch, deformed, mutated, ugly, disfigured",
134
+ },
135
+ {
136
+ "name": "Photographic",
137
+ "prompt": "cinematic photo, 35mm photograph, film, bokeh, professional, 4k, highly detailed",
138
+ "negative_prompt": "drawing, painting, crayon, sketch, graphite, impressionist, noisy, blurry, soft, deformed, ugly",
139
+ },
140
+ {
141
+ "name": "Anime",
142
+ "prompt": "anime artwork, anime style, key visual, vibrant, studio anime, highly detailed",
143
+ "negative_prompt": "photo, deformed, black and white, realism, disfigured, low contrast",
144
+ },
145
+ {
146
+ "name": "Manga",
147
+ "prompt": "manga style, vibrant, high-energy, detailed, iconic, Japanese comic style",
148
+ "negative_prompt": "ugly, deformed, noisy, blurry, low contrast, realism, photorealistic, Western comic style",
149
+ },
150
+ {
151
+ "name": "Digital Art",
152
+ "prompt": "concept art, digital artwork, illustrative, painterly, matte painting, highly detailed",
153
+ "negative_prompt": "photo, photorealistic, realism, ugly",
154
+ },
155
+ {
156
+ "name": "Pixel art",
157
+ "prompt": "pixel-art, low-res, blocky, pixel art style, 8-bit graphics",
158
+ "negative_prompt": "sloppy, messy, blurry, noisy, highly detailed, ultra textured, photo, realistic",
159
+ },
160
+ {
161
+ "name": "Fantasy art",
162
+ "prompt": "ethereal fantasy concept art, magnificent, celestial, ethereal, painterly, epic, majestic, magical, fantasy art, cover art, dreamy",
163
+ "negative_prompt": "photographic, realistic, realism, 35mm film, dslr, cropped, frame, text, deformed, glitch, noise, noisy, off-center, deformed, cross-eyed, closed eyes, bad anatomy, ugly, disfigured, sloppy, duplicate, mutated, black and white",
164
+ },
165
+ {
166
+ "name": "Neonpunk",
167
+ "prompt": "neonpunk style, cyberpunk, vaporwave, neon, vibes, vibrant, stunningly beautiful, crisp, detailed, sleek, ultramodern, magenta highlights, dark purple shadows, high contrast, cinematic, ultra detailed, intricate, professional",
168
+ "negative_prompt": "painting, drawing, illustration, glitch, deformed, mutated, cross-eyed, ugly, disfigured",
169
+ },
170
+ {
171
+ "name": "3D Model",
172
+ "prompt": "professional 3d model, octane render, highly detailed, volumetric, dramatic lighting",
173
+ "negative_prompt": "ugly, deformed, noisy, low poly, blurry, painting",
174
+ },
175
+ ]
176
+
177
+ preset_styles = {k["name"]: (k["prompt"], k["negative_prompt"]) for k in style_list}
178
+ preset_quality = {k["name"]: (k["prompt"], k["negative_prompt"]) for k in quality_prompt_list}
179
+
180
+
181
+ def process_style_prompt(prompt: str, neg_prompt: str, styles_key: str = "None", quality_key: str = "None", type: str = "None"):
182
+ def to_list(s):
183
+ return [x.strip() for x in s.split(",") if not s == ""]
184
+
185
+ def list_sub(a, b):
186
+ return [e for e in a if e not in b]
187
+
188
+ def list_uniq(l):
189
+ return sorted(set(l), key=l.index)
190
+
191
+ animagine_ps = to_list("anime artwork, anime style, key visual, vibrant, studio anime, highly detailed, masterpiece, best quality, very aesthetic, absurdres")
192
+ animagine_nps = to_list("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]")
193
+ pony_ps = to_list("source_anime, score_9, score_8_up, score_7_up, masterpiece, best quality, very aesthetic, absurdres")
194
+ pony_nps = to_list("source_pony, source_furry, source_cartoon, score_6, score_5, score_4, busty, ugly face, mutated hands, low res, blurry face, black and white, the simpsons, overwatch, apex legends")
195
+ prompts = to_list(prompt)
196
+ neg_prompts = to_list(neg_prompt)
197
+
198
+ all_styles_ps = []
199
+ all_styles_nps = []
200
+ for d in style_list:
201
+ all_styles_ps.extend(to_list(str(d.get("prompt", ""))))
202
+ all_styles_nps.extend(to_list(str(d.get("negative_prompt", ""))))
203
+
204
+ all_quality_ps = []
205
+ all_quality_nps = []
206
+ for d in quality_prompt_list:
207
+ all_quality_ps.extend(to_list(str(d.get("prompt", ""))))
208
+ all_quality_nps.extend(to_list(str(d.get("negative_prompt", ""))))
209
+
210
+ quality_ps = to_list(preset_quality[quality_key][0])
211
+ quality_nps = to_list(preset_quality[quality_key][1])
212
+ styles_ps = to_list(preset_styles[styles_key][0])
213
+ styles_nps = to_list(preset_styles[styles_key][1])
214
+
215
+ prompts = list_sub(prompts, animagine_ps + pony_ps + all_styles_ps + all_quality_ps)
216
+ neg_prompts = list_sub(neg_prompts, animagine_nps + pony_nps + all_styles_nps + all_quality_nps)
217
+
218
+ last_empty_p = [""] if not prompts and type != "None" and styles_key != "None" and quality_key != "None" else []
219
+ last_empty_np = [""] if not neg_prompts and type != "None" and styles_key != "None" and quality_key != "None" else []
220
+
221
+ if type == "Animagine":
222
+ prompts = prompts + animagine_ps
223
+ neg_prompts = neg_prompts + animagine_nps
224
+ elif type == "Pony":
225
+ prompts = prompts + pony_ps
226
+ neg_prompts = neg_prompts + pony_nps
227
+
228
+ prompts = prompts + styles_ps + quality_ps
229
+ neg_prompts = neg_prompts + styles_nps + quality_nps
230
+
231
+ prompt = ", ".join(list_uniq(prompts) + last_empty_p)
232
+ neg_prompt = ", ".join(list_uniq(neg_prompts) + last_empty_np)
233
+
234
+ return prompt, neg_prompt
235
+