P01yH3dr0n commited on
Commit
c34bc06
1 Parent(s): 84236ad

multiple vibe

Browse files
Files changed (2) hide show
  1. app.py +29 -11
  2. utils.py +8 -8
app.py CHANGED
@@ -55,10 +55,29 @@ def control_ui():
55
  with gr.Row():
56
  with gr.Column():
57
  with gr.Accordion('风格迁移', open=False):
58
- ref_image = gr.Image(label="上传图片", value=None, sources=["upload", "clipboard", "webcam"], interactive=True, type="pil")
59
- info_extract = gr.Slider(label='参考信息提取', value=1, minimum=0, maximum=1, step=0.1)
60
- ref_str = gr.Slider(label='参考强度', value=0.6, minimum=0, maximum=1, step=0.1)
61
- reuse_img_vibe = gr.Button(value='使用上一次生成的图片')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  with gr.Accordion('附加输入', open=False):
63
  with gr.Tab('图生图') as i2i:
64
  i2i_image = gr.Image(label="上传图片", value=None, sources=["upload", "clipboard", "webcam"], interactive=True, type="pil")
@@ -95,15 +114,15 @@ def control_ui():
95
  height.change(lambda w, h: w if w*h<=1024*1024 else (1024*1024//h//64)*64, [width, height], width)
96
  i2i.select(lambda: 'i2i', inputs=None, outputs=selection)
97
  inp.select(lambda: 'inp', inputs=None, outputs=selection)
98
- return gen_btn, [prompt, quality_tags, neg_prompt, seed, scale, width, height, steps, sampler, scheduler, smea, dyn, dyn_threshold, cfg_rescale, ref_image, info_extract, ref_str, i2i_image, i2i_str, i2i_noise, overlay, inp_img, selection], [save, rand_seed, reuse_seed, reuse_img_vibe, reuse_img_i2i, reuse_img_inp]
99
 
100
- def generate(prompt, quality_tags, neg_prompt, seed, scale, width, height, steps, sampler, scheduler, smea, dyn, dyn_threshold, cfg_rescale, ref_image, info_extract, ref_str, i2i_image, i2i_str, i2i_noise, overlay, inp_img, selection):
101
  global today_count
102
  set_token(os.environ.get('token'))
103
  img_data, payload = generate_novelai_image(
104
  f"{prompt}, {quality_tags}", neg_prompt, seed, scale,
105
  width, height, steps, sampler, scheduler,
106
- smea, dyn, dyn_threshold, cfg_rescale, ref_image, info_extract, ref_str,
107
  i2i_image, i2i_str, i2i_noise, overlay, inp_img, selection
108
  )
109
  if not isinstance(img_data, bytes):
@@ -145,10 +164,9 @@ def main_ui():
145
  image, info = preview_ui()
146
  gen_btn.click(generate, paras, [image, info], concurrency_limit=1)
147
  others[2].click(lambda o, s: o if len(s) == 0 else s['parameters']['seed'], inputs=[paras[3], info], outputs=paras[3])
148
- others[3].click(lambda i: i, inputs=image, outputs=paras[14])
149
- others[4].click(lambda i: i, inputs=image, outputs=paras[17])
150
- others[5].click(lambda i: gr.ImageEditor(value=i), inputs=image, outputs=paras[21])
151
- image.change(rename_save_img, inputs=[image, info, others[0]], outputs=image)
152
  return page, paras[:14]
153
 
154
  def util_ui():
 
55
  with gr.Row():
56
  with gr.Column():
57
  with gr.Accordion('风格迁移', open=False):
58
+ ref_images = gr.Gallery(label="上传单(多)张图片", format="png", value=None, interactive=True, type="pil")
59
+ info_extracts = gr.State([])
60
+ ref_strs = gr.State([])
61
+ @gr.render(inputs=ref_images, triggers=[ref_images.upload, ref_images.change])
62
+ def multiple_vibes(images):
63
+ if images is None:
64
+ return
65
+ else:
66
+ exts = []
67
+ strs = []
68
+ for i, _ in enumerate(images):
69
+ with gr.Row():
70
+ extract = gr.Slider(label=f"图片{i + 1} 参考信息提取", value=1, minimum=0, maximum=1, step=0.1, interactive=True)
71
+ strength = gr.Slider(label=f"图片{i + 1} 参考强度", value=0.6, minimum=0, maximum=1, step=0.1, interactive=True)
72
+ exts.append(extract)
73
+ strs.append(strength)
74
+ def dynparas(*args):
75
+ return list(args)
76
+ for e, s in zip(exts, strs):
77
+ e.change(fn=dynparas, inputs=exts, outputs=info_extracts)
78
+ s.change(fn=dynparas, inputs=strs, outputs=ref_strs)
79
+ ref_images.change(lambda l: ([], []) if l is None else ([1]*len(l), [0.6]*len(l)), inputs=ref_images, outputs=[info_extracts, ref_strs])
80
+ ref_images.upload(lambda l: ([], []) if l is None else ([1]*len(l), [0.6]*len(l)), inputs=ref_images, outputs=[info_extracts, ref_strs])
81
  with gr.Accordion('附加输入', open=False):
82
  with gr.Tab('图生图') as i2i:
83
  i2i_image = gr.Image(label="上传图片", value=None, sources=["upload", "clipboard", "webcam"], interactive=True, type="pil")
 
114
  height.change(lambda w, h: w if w*h<=1024*1024 else (1024*1024//h//64)*64, [width, height], width)
115
  i2i.select(lambda: 'i2i', inputs=None, outputs=selection)
116
  inp.select(lambda: 'inp', inputs=None, outputs=selection)
117
+ return gen_btn, [prompt, quality_tags, neg_prompt, seed, scale, width, height, steps, sampler, scheduler, smea, dyn, dyn_threshold, cfg_rescale, ref_images, info_extracts, ref_strs, i2i_image, i2i_str, i2i_noise, overlay, inp_img, selection], [save, rand_seed, reuse_seed, reuse_img_i2i, reuse_img_inp]
118
 
119
+ def generate(prompt, quality_tags, neg_prompt, seed, scale, width, height, steps, sampler, scheduler, smea, dyn, dyn_threshold, cfg_rescale, ref_images, info_extracts, ref_strs, i2i_image, i2i_str, i2i_noise, overlay, inp_img, selection):
120
  global today_count
121
  set_token(os.environ.get('token'))
122
  img_data, payload = generate_novelai_image(
123
  f"{prompt}, {quality_tags}", neg_prompt, seed, scale,
124
  width, height, steps, sampler, scheduler,
125
+ smea, dyn, dyn_threshold, cfg_rescale, ref_images, info_extracts, ref_strs,
126
  i2i_image, i2i_str, i2i_noise, overlay, inp_img, selection
127
  )
128
  if not isinstance(img_data, bytes):
 
164
  image, info = preview_ui()
165
  gen_btn.click(generate, paras, [image, info], concurrency_limit=1)
166
  others[2].click(lambda o, s: o if len(s) == 0 else s['parameters']['seed'], inputs=[paras[3], info], outputs=paras[3])
167
+ others[3].click(lambda i: i, inputs=image, outputs=paras[17])
168
+ others[4].click(lambda i: gr.ImageEditor(value=i), inputs=image, outputs=paras[21])
169
+ image.change(rename_save_img, inputs=[image, info, others[0]], outputs=image, trigger_mode="once")
 
170
  return page, paras[:14]
171
 
172
  def util_ui():
utils.py CHANGED
@@ -39,9 +39,9 @@ def generate_novelai_image(
39
  dyn=False,
40
  dyn_threshold=False,
41
  cfg_rescale=0,
42
- ref_image=None,
43
- info_extract=1,
44
- ref_str=0.6,
45
  i2i_image=None,
46
  i2i_str=0.7,
47
  i2i_noise=0,
@@ -77,17 +77,17 @@ def generate_novelai_image(
77
  "noise": i2i_noise,
78
  "noise_schedule": schedule,
79
  "qualityToggle": True,
80
- "reference_information_extracted": info_extract,
81
- "reference_strength": ref_str,
82
  "seed": seed,
83
  "sm": smea,
84
  "sm_dyn": dyn,
85
  "uncond_scale": 1,
86
- "add_original_image": True
87
  }
88
  }
89
- if ref_image is not None:
90
- payload['parameters']['reference_image'] = image2base64(ref_image)
91
  if selection == 'inp' and inp_img['background'].getextrema()[3][1] > 0:
92
  payload['action'] = "infill"
93
  payload['model'] = 'nai-diffusion-3-inpainting'
 
39
  dyn=False,
40
  dyn_threshold=False,
41
  cfg_rescale=0,
42
+ ref_images=None,
43
+ info_extracts=[],
44
+ ref_strs=[],
45
  i2i_image=None,
46
  i2i_str=0.7,
47
  i2i_noise=0,
 
77
  "noise": i2i_noise,
78
  "noise_schedule": schedule,
79
  "qualityToggle": True,
80
+ "reference_information_extracted_multiple": info_extracts,
81
+ "reference_strength_multiple": ref_strs,
82
  "seed": seed,
83
  "sm": smea,
84
  "sm_dyn": dyn,
85
  "uncond_scale": 1,
86
+ "add_original_image": overlay
87
  }
88
  }
89
+ if ref_images is not None:
90
+ payload['parameters']['reference_image_multiple'] = [image2base64(image[0]) for image in ref_images]
91
  if selection == 'inp' and inp_img['background'].getextrema()[3][1] > 0:
92
  payload['action'] = "infill"
93
  payload['model'] = 'nai-diffusion-3-inpainting'