John6666 commited on
Commit
cfd53e3
β€’
1 Parent(s): 4c2ebc7

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +33 -16
  2. multit2i.py +102 -5
app.py CHANGED
@@ -7,36 +7,33 @@ from multit2i import (
7
  change_model,
8
  get_model_info_md,
9
  loaded_models,
 
 
 
 
 
 
10
  )
11
 
12
 
13
  models = [
14
- 'cagliostrolab/animagine-xl-3.1',
15
- 'votepurchase/ponyDiffusionV6XL',
16
  'yodayo-ai/kivotos-xl-2.0',
17
  'yodayo-ai/holodayo-xl-2.1',
18
- 'stabilityai/stable-diffusion-xl-base-1.0',
 
19
  'eienmojiki/Anything-XL',
20
  'eienmojiki/Starry-XL-v5.2',
21
  'digiplay/majicMIX_sombre_v2',
22
  'digiplay/majicMIX_realistic_v7',
23
- 'digiplay/DreamShaper_8',
24
- 'digiplay/BeautifulArt_v1',
25
- 'digiplay/DarkSushi2.5D_v1',
26
- 'digiplay/darkphoenix3D_v1.1',
27
- 'digiplay/BeenYouLiteL11_diffusers',
28
  'votepurchase/counterfeitV30_v30',
29
  'Meina/MeinaMix_V11',
30
- 'Meina/MeinaUnreal_V5',
31
- 'Meina/MeinaPastel_V7',
32
- 'KBlueLeaf/Kohaku-XL-Epsilon-rev2',
33
  'KBlueLeaf/Kohaku-XL-Epsilon-rev3',
34
  'kayfahaarukku/UrangDiffusion-1.1',
35
  'Raelina/Rae-Diffusion-XL-V2',
36
  'Raelina/Raemu-XL-V4',
37
  ]
38
 
39
-
40
  # Examples:
41
  #models = ['yodayo-ai/kivotos-xl-2.0', 'yodayo-ai/holodayo-xl-2.1'] # specific models
42
  #models = find_model_list("John6666", [], "", "last_modified", 20) # John6666's latest 20 models
@@ -56,14 +53,31 @@ with gr.Blocks(theme="NoCrypt/miku@>=1.2.2", css=css) as demo:
56
  with gr.Column():
57
  model_name = gr.Dropdown(label="Select Model", choices=list(loaded_models.keys()), value=list(loaded_models.keys())[0], allow_custom_value=True)
58
  model_info = gr.Markdown(value=get_model_info_md(list(loaded_models.keys())[0]))
59
- image_num = gr.Slider(label="Number of Images", minimum=1, maximum=8, value=1, step=1)
60
- recom_prompt = gr.Checkbox(label="Recommended Prompt", value=True)
 
 
 
 
 
 
61
  prompt = gr.Text(label="Prompt", lines=1, max_lines=8, placeholder="1girl, solo, ...")
 
62
  run_button = gr.Button("Generate Image")
63
  results = gr.Gallery(label="Gallery", interactive=False, show_download_button=True, show_share_button=False,
64
  container=True, format="png", object_fit="contain")
65
  image_files = gr.Files(label="Download", interactive=False)
66
- clear_results = gr.Button("Clear Gallery and Download")
 
 
 
 
 
 
 
 
 
 
67
  gr.Markdown(
68
  f"""This demo was created in reference to the following demos.
69
  - [Nymbo/Flood](https://huggingface.co/spaces/Nymbo/Flood).
@@ -78,13 +92,16 @@ This is due to the time it takes for Gradio to generate an example image to cach
78
  gr.on(
79
  triggers=[run_button.click, prompt.submit],
80
  fn=infer_multi,
81
- inputs=[prompt, model_name, recom_prompt, image_num, results],
 
82
  outputs=[results],
83
  queue=True,
84
  show_progress="full",
85
  show_api=True,
86
  ).success(save_gallery_images, [results], [results, image_files], queue=False, show_api=False)
87
  clear_results.click(lambda: (None, None), None, [results, image_files], queue=False, show_api=False)
 
 
88
 
89
  demo.queue()
90
  demo.launch()
 
7
  change_model,
8
  get_model_info_md,
9
  loaded_models,
10
+ get_positive_prefix,
11
+ get_positive_suffix,
12
+ get_negative_prefix,
13
+ get_negative_suffix,
14
+ get_recom_prompt_type,
15
+ set_recom_prompt_preset,
16
  )
17
 
18
 
19
  models = [
 
 
20
  'yodayo-ai/kivotos-xl-2.0',
21
  'yodayo-ai/holodayo-xl-2.1',
22
+ 'cagliostrolab/animagine-xl-3.1',
23
+ 'votepurchase/ponyDiffusionV6XL',
24
  'eienmojiki/Anything-XL',
25
  'eienmojiki/Starry-XL-v5.2',
26
  'digiplay/majicMIX_sombre_v2',
27
  'digiplay/majicMIX_realistic_v7',
 
 
 
 
 
28
  'votepurchase/counterfeitV30_v30',
29
  'Meina/MeinaMix_V11',
 
 
 
30
  'KBlueLeaf/Kohaku-XL-Epsilon-rev3',
31
  'kayfahaarukku/UrangDiffusion-1.1',
32
  'Raelina/Rae-Diffusion-XL-V2',
33
  'Raelina/Raemu-XL-V4',
34
  ]
35
 
36
+ models = ['Raelina/Rae-Diffusion-XL-V2']
37
  # Examples:
38
  #models = ['yodayo-ai/kivotos-xl-2.0', 'yodayo-ai/holodayo-xl-2.1'] # specific models
39
  #models = find_model_list("John6666", [], "", "last_modified", 20) # John6666's latest 20 models
 
53
  with gr.Column():
54
  model_name = gr.Dropdown(label="Select Model", choices=list(loaded_models.keys()), value=list(loaded_models.keys())[0], allow_custom_value=True)
55
  model_info = gr.Markdown(value=get_model_info_md(list(loaded_models.keys())[0]))
56
+ with gr.Accordion("Advanced settings", open=False):
57
+ image_num = gr.Slider(label="Number of Images", minimum=1, maximum=8, value=1, step=1)
58
+ with gr.Accordion("Recommended Prompt"):
59
+ recom_prompt_preset = gr.Radio(label="Set Presets", choices=get_recom_prompt_type(), value="Common")
60
+ positive_prefix = gr.CheckboxGroup(label="Use Positive Prefix", choices=get_positive_prefix(), value=[])
61
+ positive_suffix = gr.CheckboxGroup(label="Use Positive Suffix", choices=get_positive_suffix(), value=["Common"])
62
+ negative_prefix = gr.CheckboxGroup(label="Use Negative Prefix", choices=get_negative_prefix(), value=[], visible=False)
63
+ negative_suffix = gr.CheckboxGroup(label="Use Negative Suffix", choices=get_negative_suffix(), value=["Common"], visible=False)
64
  prompt = gr.Text(label="Prompt", lines=1, max_lines=8, placeholder="1girl, solo, ...")
65
+ neg_prompt = gr.Text(label="Negative Prompt", lines=1, max_lines=8, placeholder="", visible=False)
66
  run_button = gr.Button("Generate Image")
67
  results = gr.Gallery(label="Gallery", interactive=False, show_download_button=True, show_share_button=False,
68
  container=True, format="png", object_fit="contain")
69
  image_files = gr.Files(label="Download", interactive=False)
70
+ clear_results = gr.Button("Clear Gallery / Download")
71
+ examples = gr.Examples(
72
+ examples = [
73
+ ["souryuu asuka langley, 1girl, 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"],
74
+ ["sailor moon, magical girl transformation, sparkles and ribbons, soft pastel colors, crescent moon motif, starry night sky background, shoujo manga style"],
75
+ ["kafuu chino, 1girl, solo"],
76
+ ["1girl"],
77
+ ["beautiful sunset"],
78
+ ],
79
+ inputs=[prompt],
80
+ )
81
  gr.Markdown(
82
  f"""This demo was created in reference to the following demos.
83
  - [Nymbo/Flood](https://huggingface.co/spaces/Nymbo/Flood).
 
92
  gr.on(
93
  triggers=[run_button.click, prompt.submit],
94
  fn=infer_multi,
95
+ inputs=[prompt, neg_prompt, results, image_num, model_name,
96
+ positive_prefix, positive_suffix, negative_prefix, negative_suffix],
97
  outputs=[results],
98
  queue=True,
99
  show_progress="full",
100
  show_api=True,
101
  ).success(save_gallery_images, [results], [results, image_files], queue=False, show_api=False)
102
  clear_results.click(lambda: (None, None), None, [results, image_files], queue=False, show_api=False)
103
+ recom_prompt_preset.change(set_recom_prompt_preset, [recom_prompt_preset],
104
+ [positive_prefix, positive_suffix, negative_prefix, negative_suffix], queue=False, show_api=False)
105
 
106
  demo.queue()
107
  demo.launch()
multit2i.py CHANGED
@@ -7,6 +7,10 @@ loaded_models = {}
7
  model_info_dict = {}
8
 
9
 
 
 
 
 
10
  def list_sub(a, b):
11
  return [e for e in a if e not in b]
12
 
@@ -143,6 +147,98 @@ def load_models(models: list, limit: int=5):
143
  loop.close()
144
 
145
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
  def get_model_info_md(model_name: str):
147
  if model_name in model_info_dict.keys(): return model_info_dict[model_name].get("md", "")
148
 
@@ -152,19 +248,18 @@ def change_model(model_name: str):
152
  return get_model_info_md(model_name)
153
 
154
 
155
- def infer(prompt: str, model_name: str, recom_prompt: bool, progress=gr.Progress(track_tqdm=True)):
156
  from PIL import Image
157
  import random
158
  seed = ""
159
  rand = random.randint(1, 500)
160
  for i in range(rand):
161
  seed += " "
162
- rprompt = ", highly detailed, masterpiece, best quality, very aesthetic, absurdres, " if recom_prompt else ""
163
  caption = model_name.split("/")[-1]
164
  try:
165
  model = load_model(model_name)
166
  if not model: return (Image.Image(), None)
167
- image_path = model(prompt + rprompt + seed)
168
  image = Image.open(image_path).convert('RGB')
169
  except Exception as e:
170
  print(e)
@@ -172,9 +267,11 @@ def infer(prompt: str, model_name: str, recom_prompt: bool, progress=gr.Progress
172
  return (image, caption)
173
 
174
 
175
- def infer_multi(prompt: str, model_name: str, recom_prompt: bool, image_num: float, results: list, progress=gr.Progress(track_tqdm=True)):
 
176
  image_num = int(image_num)
177
  images = results if results else []
 
178
  for i in range(image_num):
179
- images.append(infer(prompt, model_name, recom_prompt))
180
  yield images
 
7
  model_info_dict = {}
8
 
9
 
10
+ def to_list(s):
11
+ return [x.strip() for x in s.split(",")]
12
+
13
+
14
  def list_sub(a, b):
15
  return [e for e in a if e not in b]
16
 
 
147
  loop.close()
148
 
149
 
150
+ positive_prefix = {
151
+ "Pony": to_list("score_9, score_8_up, score_7_up"),
152
+ "Pony Anime": to_list("source_anime, score_9, score_8_up, score_7_up"),
153
+ }
154
+ positive_suffix = {
155
+ "Common": to_list("highly detailed, masterpiece, best quality, very aesthetic, absurdres"),
156
+ "Anime": to_list("anime artwork, anime style, studio anime, highly detailed"),
157
+ }
158
+ negative_prefix = {
159
+ "Pony": to_list("score_6, score_5, score_4"),
160
+ "Pony Anime": to_list("score_6, score_5, score_4, source_pony, source_furry, source_cartoon"),
161
+ "Pony Real": to_list("score_6, score_5, score_4, source_anime, source_pony, source_furry, source_cartoon"),
162
+ }
163
+ negative_suffix = {
164
+ "Common": 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]"),
165
+ "Pony Anime": to_list("busty, ugly face, mutated hands, low res, blurry face, black and white, the simpsons, overwatch, apex legends"),
166
+ "Pony Real": to_list("ugly, airbrushed, simple background, cgi, cartoon, anime"),
167
+ }
168
+ positive_all = negative_all = []
169
+ for k, v in (positive_prefix | positive_suffix).items():
170
+ positive_all = positive_all + v + [s.replace("_", " ") for s in v]
171
+ positive_all = list_uniq(positive_all)
172
+ for k, v in (negative_prefix | negative_suffix).items():
173
+ negative_all = negative_all + v + [s.replace("_", " ") for s in v]
174
+ positive_all = list_uniq(positive_all)
175
+
176
+
177
+ def recom_prompt(prompt: str = "", neg_prompt: str = "", pos_pre: list = [], pos_suf: list = [], neg_pre: list = [], neg_suf: list = []):
178
+ def flatten(src):
179
+ return [item for row in src for item in row]
180
+ prompts = to_list(prompt)
181
+ neg_prompts = to_list(neg_prompt)
182
+ prompts = list_sub(prompts, positive_all)
183
+ neg_prompts = list_sub(neg_prompts, negative_all)
184
+ last_empty_p = [""] if not prompts and type != "None" else []
185
+ last_empty_np = [""] if not neg_prompts and type != "None" else []
186
+ prefix_ps = flatten([positive_prefix.get(s, []) for s in pos_pre])
187
+ suffix_ps = flatten([positive_suffix.get(s, []) for s in pos_suf])
188
+ prefix_nps = flatten([negative_prefix.get(s, []) for s in neg_pre])
189
+ suffix_nps = flatten([negative_suffix.get(s, []) for s in neg_suf])
190
+ prompt = ", ".join(list_uniq(prefix_ps + prompts + suffix_ps) + last_empty_p)
191
+ neg_prompt = ", ".join(list_uniq(prefix_nps + neg_prompts + suffix_nps) + last_empty_np)
192
+ return prompt, neg_prompt
193
+
194
+
195
+ recom_prompt_type = {
196
+ "None": ([], [], [], []),
197
+ "Auto": ([], [], [], []),
198
+ "Common": ([], ["Common"], [], ["Common"]),
199
+ "Animagine": ([], ["Common", "Anime"], [], ["Common"]),
200
+ "Pony": (["Pony"], ["Common"], ["Pony"], ["Common"]),
201
+ "Pony Anime": (["Pony", "Pony Anime"], ["Common", "Anime"], ["Pony", "Pony Anime"], ["Common", "Pony Anime"]),
202
+ "Pony Real": (["Pony"], ["Common"], ["Pony", "Pony Real"], ["Common", "Pony Real"]),
203
+ }
204
+
205
+
206
+ enable_auto_recom_prompt = False
207
+ def insert_recom_prompt(prompt: str = "", neg_prompt: str = "", type: str = "None"):
208
+ global enable_auto_recom_prompt
209
+ if type == "Auto": enable_auto_recom_prompt = True
210
+ else: enable_auto_recom_prompt = False
211
+ pos_pre, pos_suf, neg_pre, neg_suf = recom_prompt_type.get(type, ([], [], [], []))
212
+ return recom_prompt(prompt, neg_prompt, pos_pre, pos_suf, neg_pre, neg_suf)
213
+
214
+
215
+ def set_recom_prompt_preset(type: str = "None"):
216
+ pos_pre, pos_suf, neg_pre, neg_suf = recom_prompt_type.get(type, ([], [], [], []))
217
+ return pos_pre, pos_suf, neg_pre, neg_suf
218
+
219
+
220
+ def get_recom_prompt_type():
221
+ type = list(recom_prompt_type.keys())
222
+ type.remove("Auto")
223
+ return type
224
+
225
+
226
+ def get_positive_prefix():
227
+ return list(positive_prefix.keys())
228
+
229
+
230
+ def get_positive_suffix():
231
+ return list(positive_suffix.keys())
232
+
233
+
234
+ def get_negative_prefix():
235
+ return list(negative_prefix.keys())
236
+
237
+
238
+ def get_negative_suffix():
239
+ return list(negative_suffix.keys())
240
+
241
+
242
  def get_model_info_md(model_name: str):
243
  if model_name in model_info_dict.keys(): return model_info_dict[model_name].get("md", "")
244
 
 
248
  return get_model_info_md(model_name)
249
 
250
 
251
+ def infer(prompt: str, neg_prompt: str, model_name: str, progress=gr.Progress(track_tqdm=True)):
252
  from PIL import Image
253
  import random
254
  seed = ""
255
  rand = random.randint(1, 500)
256
  for i in range(rand):
257
  seed += " "
 
258
  caption = model_name.split("/")[-1]
259
  try:
260
  model = load_model(model_name)
261
  if not model: return (Image.Image(), None)
262
+ image_path = model(prompt + seed)
263
  image = Image.open(image_path).convert('RGB')
264
  except Exception as e:
265
  print(e)
 
267
  return (image, caption)
268
 
269
 
270
+ def infer_multi(prompt: str, neg_prompt: str, results: list, image_num: float, model_name: str,
271
+ pos_pre: list = [], pos_suf: list = [], neg_pre: list = [], neg_suf: list = [], progress=gr.Progress(track_tqdm=True)):
272
  image_num = int(image_num)
273
  images = results if results else []
274
+ prompt, neg_prompt = recom_prompt(prompt, neg_prompt, pos_pre, pos_suf, neg_pre, neg_suf)
275
  for i in range(image_num):
276
+ images.append(infer(prompt, neg_prompt, model_name, recom_prompt))
277
  yield images