root commited on
Commit
77da620
1 Parent(s): 7f68ca3

add img2img

Browse files
Files changed (1) hide show
  1. app.py +74 -8
app.py CHANGED
@@ -7,6 +7,67 @@ import json
7
  from PIL import Image
8
  import ui_functions as uifn
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  def read_content(file_path: str) -> str:
11
  """read the content of target file
12
  """
@@ -60,6 +121,11 @@ def request_images(raw_text, class_draw, style_draw, batch_size):
60
 
61
  return images
62
 
 
 
 
 
 
63
  examples = [
64
  '水墨蝴蝶和牡丹花,国画',
65
  '苍劲有力的墨竹,国画',
@@ -292,14 +358,14 @@ if __name__ == "__main__":
292
  # img2img_image_mask
293
  # )
294
 
295
- output_txt2img_copy_to_input_btn.click(
296
- uifn.copy_img_to_input,
297
- [output_txt2img_gallery],
298
- [img2img_image_editor, img2img_image_mask, tabs],
299
- _js=call_JS("moveImageFromGallery",
300
- fromId="txt2img_gallery_output",
301
- toId="img2img_editor")
302
- )
303
 
304
  output_img2img_copy_to_input_btn.click(
305
  uifn.copy_img_to_edit,
 
7
  from PIL import Image
8
  import ui_functions as uifn
9
 
10
+ txt2img_defaults = {
11
+ 'prompt': '',
12
+ 'ddim_steps': 50,
13
+ 'toggles': [1, 2, 3],
14
+ 'sampler_name': 'k_lms',
15
+ 'ddim_eta': 0.0,
16
+ 'n_iter': 1,
17
+ 'batch_size': 1,
18
+ 'cfg_scale': 7.5,
19
+ 'seed': '',
20
+ 'height': 512,
21
+ 'width': 512,
22
+ 'fp': None,
23
+ 'variant_amount': 0.0,
24
+ 'variant_seed': '',
25
+ 'submit_on_enter': 'Yes',
26
+ }
27
+
28
+ img2img_defaults = {
29
+ 'prompt': '',
30
+ 'ddim_steps': 50,
31
+ 'toggles': [1, 4, 5],
32
+ 'sampler_name': 'k_lms',
33
+ 'ddim_eta': 0.0,
34
+ 'n_iter': 1,
35
+ 'batch_size': 1,
36
+ 'cfg_scale': 5.0,
37
+ 'denoising_strength': 0.75,
38
+ 'mask_mode': 1,
39
+ 'resize_mode': 0,
40
+ 'seed': '',
41
+ 'height': 512,
42
+ 'width': 512,
43
+ 'fp': None,
44
+ }
45
+ sample_img2img = None
46
+ job_manager = None
47
+ RealESRGAN = True
48
+ show_embeddings = False
49
+
50
+ img2img_resize_modes = [
51
+ "Just resize",
52
+ "Crop and resize",
53
+ "Resize and fill",
54
+ ]
55
+
56
+ img2img_toggles = [
57
+ 'Create prompt matrix (separate multiple prompts using |, and get all combinations of them)',
58
+ 'Normalize Prompt Weights (ensure sum of weights add up to 1.0)',
59
+ 'Loopback (use images from previous batch when creating next batch)',
60
+ 'Random loopback seed',
61
+ 'Save individual images',
62
+ 'Save grid',
63
+ 'Sort samples by prompt',
64
+ 'Write sample info files',
65
+ 'Write sample info to one file',
66
+ 'jpg samples',
67
+ ]
68
+
69
+ img2img_toggle_defaults = [img2img_toggles[i] for i in img2img_defaults['toggles']]
70
+
71
  def read_content(file_path: str) -> str:
72
  """read the content of target file
73
  """
 
121
 
122
  return images
123
 
124
+ def call_JS(sd_method, **kwargs):
125
+ param_str = json.dumps(kwargs)
126
+ return f"async (...x) => {{ return await SD.{sd_method}({{ x, ...{param_str} }}) ?? []; }}"
127
+
128
+
129
  examples = [
130
  '水墨蝴蝶和牡丹花,国画',
131
  '苍劲有力的墨竹,国画',
 
358
  # img2img_image_mask
359
  # )
360
 
361
+ # output_txt2img_copy_to_input_btn.click(
362
+ # uifn.copy_img_to_input,
363
+ # [output_txt2img_gallery],
364
+ # [img2img_image_editor, img2img_image_mask, tabs],
365
+ # _js=call_JS("moveImageFromGallery",
366
+ # fromId="txt2img_gallery_output",
367
+ # toId="img2img_editor")
368
+ # )
369
 
370
  output_img2img_copy_to_input_btn.click(
371
  uifn.copy_img_to_edit,