John6666 commited on
Commit
a1dbfb7
·
verified ·
1 Parent(s): 65fa164

Upload 5 files

Browse files
Files changed (4) hide show
  1. app.py +7 -7
  2. model_dict.json +0 -0
  3. modutils.py +0 -43
  4. tagger.py +64 -7
app.py CHANGED
@@ -410,6 +410,7 @@ from tagger import (
410
  convert_danbooru_to_e621_prompt,
411
  remove_specific_prompt,
412
  insert_recom_prompt,
 
413
  compose_prompt_to_copy,
414
  translate_prompt,
415
  select_random_character,
@@ -437,7 +438,6 @@ from modutils import (
437
  preset_quality,
438
  preset_sampler_setting,
439
  set_quick_presets,
440
- insert_model_recom_prompt,
441
  )
442
  def description_ui():
443
  gr.Markdown(
@@ -911,14 +911,14 @@ with gr.Blocks(theme="NoCrypt/miku@>=1.2.2", elem_id="main", css=CSS) as app:
911
  with gr.Accordion("Negative prompt, etc.", open=False) as menu_negative:
912
  neg_prompt_gui = gr.Textbox(lines=3, placeholder="lowres, (bad), ...", label="Negative prompt", show_copy_button=True)
913
  translate_prompt_button = gr.Button(value="Translate prompt to English", size="sm", variant="secondary")
914
- insert_prompt_gui = gr.Radio(label="Insert reccomended positive / negative prompt", choices=["None", "Animagine", "Pony"], value="None", interactive=True, scale=2)
915
  with gr.Accordion(label="Advanced options", open=False):
916
  prompt_type_gui = gr.Radio(label="Convert tags to", choices=["danbooru", "e621"], value="e621", visible=False)
917
  prompt_type_button = gr.Button(value="Convert prompt to Pony e621 style", size="sm", variant="secondary")
918
  with gr.Row():
919
  character_dbt = gr.Textbox(lines=1, placeholder="kafuu chino, ...", label="Character names")
920
  series_dbt = gr.Textbox(lines=1, placeholder="Is the order a rabbit?, ...", label="Series names")
921
- random_character_gui = gr.Button(value="Pick a random character 🎲", size="sm")
922
  model_name_dbt = gr.Dropdown(label="Model", choices=list(V2_ALL_MODELS.keys()), value=list(V2_ALL_MODELS.keys())[0], visible=False)
923
  aspect_ratio_dbt = gr.Radio(label="Aspect ratio", choices=list(V2_ASPECT_RATIO_OPTIONS), value="square", visible=False)
924
  length_dbt = gr.Radio(label="Length", choices=list(V2_LENGTH_OPTIONS), value="very_long", visible=False)
@@ -926,12 +926,12 @@ with gr.Blocks(theme="NoCrypt/miku@>=1.2.2", elem_id="main", css=CSS) as app:
926
  ban_tags_dbt = gr.Textbox(label="Ban tags", placeholder="alternate costumen, ...", value="futanari, censored, furry, furrification", visible=False)
927
  elapsed_time_dbt = gr.Markdown(label="Elapsed time", value="", visible=False)
928
  copy_button_dbt = gr.Button(value="Copy to clipboard", visible=False)
929
- generate_db_random_button = gr.Button(value="Generate random prompt 🎲", size="sm", variant="secondary")
930
  rating_dbt = gr.Radio(label="Rating", choices=list(V2_RATING_OPTIONS), value="sfw")
931
  with gr.Row():
932
- set_params_gui = gr.Button(value="↙️")
933
- clear_prompt_gui = gr.Button(value="🗑️")
934
- set_random_seed = gr.Button(value="🎲")
935
 
936
  generate_button = gr.Button(value="GENERATE IMAGE", size="lg", variant="primary")
937
 
 
410
  convert_danbooru_to_e621_prompt,
411
  remove_specific_prompt,
412
  insert_recom_prompt,
413
+ insert_model_recom_prompt,
414
  compose_prompt_to_copy,
415
  translate_prompt,
416
  select_random_character,
 
438
  preset_quality,
439
  preset_sampler_setting,
440
  set_quick_presets,
 
441
  )
442
  def description_ui():
443
  gr.Markdown(
 
911
  with gr.Accordion("Negative prompt, etc.", open=False) as menu_negative:
912
  neg_prompt_gui = gr.Textbox(lines=3, placeholder="lowres, (bad), ...", label="Negative prompt", show_copy_button=True)
913
  translate_prompt_button = gr.Button(value="Translate prompt to English", size="sm", variant="secondary")
914
+ insert_prompt_gui = gr.Radio(label="Insert reccomended positive / negative prompt", choices=["None", "Auto", "Animagine", "Pony"], value="Auto", interactive=True)
915
  with gr.Accordion(label="Advanced options", open=False):
916
  prompt_type_gui = gr.Radio(label="Convert tags to", choices=["danbooru", "e621"], value="e621", visible=False)
917
  prompt_type_button = gr.Button(value="Convert prompt to Pony e621 style", size="sm", variant="secondary")
918
  with gr.Row():
919
  character_dbt = gr.Textbox(lines=1, placeholder="kafuu chino, ...", label="Character names")
920
  series_dbt = gr.Textbox(lines=1, placeholder="Is the order a rabbit?, ...", label="Series names")
921
+ random_character_gui = gr.Button(value="Pick a random character 🎲", size="sm", variant="secondary")
922
  model_name_dbt = gr.Dropdown(label="Model", choices=list(V2_ALL_MODELS.keys()), value=list(V2_ALL_MODELS.keys())[0], visible=False)
923
  aspect_ratio_dbt = gr.Radio(label="Aspect ratio", choices=list(V2_ASPECT_RATIO_OPTIONS), value="square", visible=False)
924
  length_dbt = gr.Radio(label="Length", choices=list(V2_LENGTH_OPTIONS), value="very_long", visible=False)
 
926
  ban_tags_dbt = gr.Textbox(label="Ban tags", placeholder="alternate costumen, ...", value="futanari, censored, furry, furrification", visible=False)
927
  elapsed_time_dbt = gr.Markdown(label="Elapsed time", value="", visible=False)
928
  copy_button_dbt = gr.Button(value="Copy to clipboard", visible=False)
929
+ generate_db_random_button = gr.Button(value="Generate random prompt 🎲", variant="secondary")
930
  rating_dbt = gr.Radio(label="Rating", choices=list(V2_RATING_OPTIONS), value="sfw")
931
  with gr.Row():
932
+ set_params_gui = gr.Button(value="↙️", size="sm")
933
+ clear_prompt_gui = gr.Button(value="🗑️", size="sm")
934
+ set_random_seed = gr.Button(value="🎲", size="sm")
935
 
936
  generate_button = gr.Button(value="GENERATE IMAGE", size="lg", variant="primary")
937
 
model_dict.json CHANGED
The diff for this file is too large to render. See raw diff
 
modutils.py CHANGED
@@ -872,46 +872,3 @@ def get_model_pipeline(repo_id: str):
872
  else:
873
  return default
874
 
875
-
876
- def load_model_prompt_dict():
877
- import json
878
- dict = {}
879
- with open('model_dict.json', encoding='utf-8') as f:
880
- dict = json.load(f)
881
- return dict
882
-
883
-
884
- model_prompt_dict = load_model_prompt_dict()
885
-
886
-
887
- def insert_model_recom_prompt(prompt: str = "", neg_prompt: str = "", model_name: str = "None"):
888
- def to_list(s):
889
- return [x.strip() for x in s.split(",") if not s == ""]
890
-
891
- def list_sub(a, b):
892
- return [e for e in a if e not in b]
893
-
894
- def list_uniq(l):
895
- return sorted(set(l), key=l.index)
896
-
897
- if not model_name or not model_name in model_prompt_dict.keys(): return prompt, neg_prompt
898
- animagine_ps = to_list("anime artwork, anime style, key visual, vibrant, studio anime, highly detailed, masterpiece, best quality, very aesthetic, absurdres")
899
- 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]")
900
- pony_ps = to_list("source_anime, score_9, score_8_up, score_7_up, masterpiece, best quality, very aesthetic, absurdres")
901
- 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")
902
- other_ps = to_list("anime artwork, anime style, key visual, vibrant, studio anime, highly detailed, cinematic photo, 35mm photograph, film, bokeh, professional, 4k, highly detailed")
903
- other_nps = to_list("photo, deformed, black and white, realism, disfigured, low contrast, drawing, painting, crayon, sketch, graphite, impressionist, noisy, blurry, soft, deformed, ugly")
904
- prompts = to_list(prompt)
905
- neg_prompts = to_list(neg_prompt)
906
- prompts = list_sub(prompts, animagine_ps + pony_ps + other_ps)
907
- neg_prompts = list_sub(neg_prompts, animagine_nps + pony_nps + other_nps)
908
- last_empty_p = [""] if not prompts and type != "None" else []
909
- last_empty_np = [""] if not neg_prompts and type != "None" else []
910
- ps = to_list(model_prompt_dict[model_name]["prompt"])
911
- nps = to_list(model_prompt_dict[model_name]["negative_prompt"])
912
- prompts = prompts + ps
913
- neg_prompts = neg_prompts + nps
914
- prompt = ", ".join(list_uniq(prompts) + last_empty_p)
915
- neg_prompt = ", ".join(list_uniq(neg_prompts) + last_empty_np)
916
- return prompt, neg_prompt
917
-
 
872
  else:
873
  return default
874
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
tagger.py CHANGED
@@ -227,6 +227,9 @@ def convert_tags_to_ja(input_prompt: str = ""):
227
  return ", ".join(out_tags)
228
 
229
 
 
 
 
230
  def insert_recom_prompt(prompt: str = "", neg_prompt: str = "", type: str = "None"):
231
  def to_list(s):
232
  return [x.strip() for x in s.split(",") if not s == ""]
@@ -236,7 +239,8 @@ def insert_recom_prompt(prompt: str = "", neg_prompt: str = "", type: str = "Non
236
 
237
  def list_uniq(l):
238
  return sorted(set(l), key=l.index)
239
-
 
240
  animagine_ps = to_list("anime artwork, anime style, key visual, vibrant, studio anime, highly detailed, masterpiece, best quality, very aesthetic, absurdres")
241
  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]")
242
  pony_ps = to_list("source_anime, score_9, score_8_up, score_7_up, masterpiece, best quality, very aesthetic, absurdres")
@@ -250,12 +254,16 @@ def insert_recom_prompt(prompt: str = "", neg_prompt: str = "", type: str = "Non
250
  last_empty_p = [""] if not prompts and type != "None" else []
251
  last_empty_np = [""] if not neg_prompts and type != "None" else []
252
 
253
- if type == "Animagine":
254
- prompts = prompts + animagine_ps
255
- neg_prompts = neg_prompts + animagine_nps
256
- elif type == "Pony":
257
- prompts = prompts + pony_ps
258
- neg_prompts = neg_prompts + pony_nps
 
 
 
 
259
 
260
  prompt = ", ".join(list_uniq(prompts) + last_empty_p)
261
  neg_prompt = ", ".join(list_uniq(neg_prompts) + last_empty_np)
@@ -263,6 +271,55 @@ def insert_recom_prompt(prompt: str = "", neg_prompt: str = "", type: str = "Non
263
  return prompt, neg_prompt
264
 
265
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
266
  tag_group_dict = load_dict_from_csv('tag_group.csv')
267
 
268
 
 
227
  return ", ".join(out_tags)
228
 
229
 
230
+ enable_auto_recom_prompt = True
231
+
232
+
233
  def insert_recom_prompt(prompt: str = "", neg_prompt: str = "", type: str = "None"):
234
  def to_list(s):
235
  return [x.strip() for x in s.split(",") if not s == ""]
 
239
 
240
  def list_uniq(l):
241
  return sorted(set(l), key=l.index)
242
+
243
+ global enable_auto_recom_prompt
244
  animagine_ps = to_list("anime artwork, anime style, key visual, vibrant, studio anime, highly detailed, masterpiece, best quality, very aesthetic, absurdres")
245
  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]")
246
  pony_ps = to_list("source_anime, score_9, score_8_up, score_7_up, masterpiece, best quality, very aesthetic, absurdres")
 
254
  last_empty_p = [""] if not prompts and type != "None" else []
255
  last_empty_np = [""] if not neg_prompts and type != "None" else []
256
 
257
+ if type == "Auto":
258
+ enable_auto_recom_prompt = True
259
+ else:
260
+ enable_auto_recom_prompt = False
261
+ if type == "Animagine":
262
+ prompts = prompts + animagine_ps
263
+ neg_prompts = neg_prompts + animagine_nps
264
+ elif type == "Pony":
265
+ prompts = prompts + pony_ps
266
+ neg_prompts = neg_prompts + pony_nps
267
 
268
  prompt = ", ".join(list_uniq(prompts) + last_empty_p)
269
  neg_prompt = ", ".join(list_uniq(neg_prompts) + last_empty_np)
 
271
  return prompt, neg_prompt
272
 
273
 
274
+ def load_model_prompt_dict():
275
+ import json
276
+ dict = {}
277
+ with open('model_dict.json', encoding='utf-8') as f:
278
+ dict = json.load(f)
279
+ return dict
280
+
281
+
282
+ model_prompt_dict = load_model_prompt_dict()
283
+
284
+
285
+ def insert_model_recom_prompt(prompt: str = "", neg_prompt: str = "", model_name: str = "None"):
286
+ def to_list(s):
287
+ return [x.strip() for x in s.split(",") if not s == ""]
288
+
289
+ def list_sub(a, b):
290
+ return [e for e in a if e not in b]
291
+
292
+ def list_uniq(l):
293
+ return sorted(set(l), key=l.index)
294
+
295
+ if not model_name or not enable_auto_recom_prompt: return prompt, neg_prompt
296
+ animagine_ps = to_list("anime artwork, anime style, key visual, vibrant, studio anime, highly detailed, masterpiece, best quality, very aesthetic, absurdres")
297
+ 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]")
298
+ pony_ps = to_list("source_anime, score_9, score_8_up, score_7_up, masterpiece, best quality, very aesthetic, absurdres")
299
+ 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")
300
+ other_ps = to_list("anime artwork, anime style, key visual, vibrant, studio anime, highly detailed, cinematic photo, 35mm photograph, film, bokeh, professional, 4k, highly detailed")
301
+ other_nps = to_list("photo, deformed, black and white, realism, disfigured, low contrast, drawing, painting, crayon, sketch, graphite, impressionist, noisy, blurry, soft, deformed, ugly")
302
+ prompts = to_list(prompt)
303
+ neg_prompts = to_list(neg_prompt)
304
+ prompts = list_sub(prompts, animagine_ps + pony_ps + other_ps)
305
+ neg_prompts = list_sub(neg_prompts, animagine_nps + pony_nps + other_nps)
306
+ last_empty_p = [""] if not prompts and type != "None" else []
307
+ last_empty_np = [""] if not neg_prompts and type != "None" else []
308
+ ps = []
309
+ nps = []
310
+ if model_name in model_prompt_dict.keys():
311
+ ps = to_list(model_prompt_dict[model_name]["prompt"])
312
+ nps = to_list(model_prompt_dict[model_name]["negative_prompt"])
313
+ else:
314
+ ps = to_list("score_9, score_8_up, score_7_up, highly detailed, masterpiece, best quality, very aesthetic, absurdres")
315
+ nps = to_list("score_6, score_5, score_4, 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]")
316
+ prompts = prompts + ps
317
+ neg_prompts = neg_prompts + nps
318
+ prompt = ", ".join(list_uniq(prompts) + last_empty_p)
319
+ neg_prompt = ", ".join(list_uniq(neg_prompts) + last_empty_np)
320
+ return prompt, neg_prompt
321
+
322
+
323
  tag_group_dict = load_dict_from_csv('tag_group.csv')
324
 
325