q6 commited on
Commit
8198c72
·
1 Parent(s): 8eda0c0

Use generation 2 names and seed

Browse files
Files changed (3) hide show
  1. API.md +2 -2
  2. app.py +18 -14
  3. workflow_api.py +2 -2
API.md CHANGED
@@ -19,7 +19,7 @@ Content-Type: application/json
19
  {"positive":"an orange cat","negative":"text, watermark"}
20
  ```
21
 
22
- Queues a passive confusion-matrix run and returns its reserved `grN.epng` path. Each numbered checkpoint gets one 20-step first pass at CFG 6 with DPM++ 2M and Karras. Diagonal `gN.epng` files contain that first pass. Each missing off-diagonal `gN-M.epng` resumes from the first-pass image, applies a 1.1 bislerp latent upscale, then runs the second checkpoint for 14 steps at CFG 5 and denoise 0.35 with the same sampler, scheduler, prompts, and aDetailer. Existing cell files are reused. The labeled grid is saved after every cell is present.
23
 
24
  ## Generate
25
 
@@ -52,7 +52,7 @@ Content-Type: application/json
52
  }
53
  ```
54
 
55
- Returns a metadata-free PNG scaled after generation by the decimal `return_scale` from `0.01` through `1`, with content type `image/png`. Use `1` for full resolution. Set either scheduler to `AlignYourSteps` to use `AlignYourStepsScheduler` with fixed model type `SDXL` and the corresponding steps and denoise values. Only `prompt` is required for the built-in site defaults. LoRAs run in array order. Each request creates a random first-pass seed and, when `upscale` is true, performs latent upscaling followed by a second sampler with another random seed. Leave `second_model` empty to reuse the first model and LoRA chain; otherwise `second_loras` applies to the selected second model. Width and height must be multiples of 8 from 64 through 2048; steps must be from 1 through 100.
56
 
57
  ## Archive
58
 
 
19
  {"positive":"an orange cat","negative":"text, watermark"}
20
  ```
21
 
22
+ Queues a passive confusion-matrix run and returns its reserved `Ngr2.epng` path. Each numbered checkpoint gets one 20-step first pass at CFG 6 with DPM++ 2M and Karras. Diagonal `Ng2.epng` files contain that first pass. Each missing off-diagonal `N-Mg2.epng` resumes from the first-pass image, applies a 1.1 bislerp latent upscale, then runs the second checkpoint for 14 steps at CFG 5 and denoise 0.35 with the same sampler, scheduler, prompts, and aDetailer. Existing cell files are reused. The labeled grid is saved after every cell is present.
23
 
24
  ## Generate
25
 
 
52
  }
53
  ```
54
 
55
+ Returns a metadata-free PNG scaled after generation by the decimal `return_scale` from `0.01` through `1`, with content type `image/png`. Use `1` for full resolution. Set either scheduler to `AlignYourSteps` to use `AlignYourStepsScheduler` with fixed model type `SDXL` and the corresponding steps and denoise values. Only `prompt` is required for the built-in site defaults. LoRAs run in array order. Every sampler uses generation seed `2`. When `upscale` is true, the request performs latent upscaling followed by a second sampler. Leave `second_model` empty to reuse the first model and LoRA chain; otherwise `second_loras` applies to the selected second model. Width and height must be multiples of 8 from 64 through 2048; steps must be from 1 through 100.
56
 
57
  ## Archive
58
 
app.py CHANGED
@@ -1,5 +1,4 @@
1
  import os
2
- import random
3
  import re
4
  import secrets
5
  import shutil
@@ -50,7 +49,12 @@ from PIL import Image, ImageDraw, ImageFilter, ImageFont
50
  from PIL.PngImagePlugin import PngInfo
51
  from pydantic import BaseModel, ConfigDict, Field
52
  from starlette.background import BackgroundTask
53
- from workflow_api import ALIGN_MODEL_TYPE, ALIGN_SCHEDULER, image_metadata
 
 
 
 
 
54
 
55
 
56
  DATA_MOUNT = Path("/data")
@@ -473,7 +477,7 @@ def generate_core(body):
473
  height=request.height,
474
  batch_size=1,
475
  )[0]
476
- first_seed = random.randrange(2**64)
477
  samples = run_sampler(
478
  model,
479
  first_seed,
@@ -502,7 +506,7 @@ def generate_core(body):
502
  positive = state["encode"].encode(clip=clip, text=request.prompt)[0]
503
  negative = state["encode"].encode(clip=clip, text=request.negative)[0]
504
 
505
- second_seed = random.randrange(2**64)
506
  samples = run_sampler(
507
  model,
508
  second_seed,
@@ -698,7 +702,7 @@ def run_adetailer(image, model, clip, negative, sampler, scheduler):
698
  pixels=image,
699
  )[0]
700
  latent["noise_mask"] = mask
701
- seed = random.randrange(2**64)
702
  samples = run_sampler(
703
  model,
704
  seed,
@@ -752,7 +756,7 @@ def generate_matrix_cell_core(body):
752
  folder = (IMAGE_DIR / request.folder).resolve()
753
  if folder.parent != IMAGE_DIR.resolve():
754
  raise ValueError("Invalid matrix folder")
755
- diagonal = folder / f"g{first_id}.epng"
756
  state["vae"] = load_vae(DEFAULT_VAE)
757
 
758
  if first_id == second_id:
@@ -774,7 +778,7 @@ def generate_matrix_cell_core(body):
774
  )[0]
775
  samples = run_sampler(
776
  model,
777
- random.randrange(2**64),
778
  MATRIX_FIRST_STEPS,
779
  MATRIX_FIRST_CFG,
780
  MATRIX_SAMPLER,
@@ -792,7 +796,7 @@ def generate_matrix_cell_core(body):
792
  release_model(first_name)
793
  return first_id
794
 
795
- output = folder / f"g{first_id}-{second_id}.epng"
796
  if output.is_file():
797
  return f"{first_id}-{second_id}"
798
 
@@ -816,7 +820,7 @@ def generate_matrix_cell_core(body):
816
  )[0]
817
  samples = run_sampler(
818
  model,
819
- random.randrange(2**64),
820
  MATRIX_SECOND_STEPS,
821
  MATRIX_SECOND_CFG,
822
  MATRIX_SAMPLER,
@@ -1035,7 +1039,7 @@ def reserve_matrix_grid(folder):
1035
  with matrix_lock:
1036
  number = 1
1037
  while (
1038
- (path / f"gr{number}.epng").exists()
1039
  or (folder, number) in matrix_grids
1040
  ):
1041
  number += 1
@@ -1065,9 +1069,9 @@ def matrix_models():
1065
 
1066
  def matrix_image_path(folder, first_id, second_id):
1067
  name = (
1068
- f"g{first_id}.epng"
1069
  if first_id == second_id
1070
- else f"g{first_id}-{second_id}.epng"
1071
  )
1072
  return IMAGE_DIR / folder / name
1073
 
@@ -1115,7 +1119,7 @@ def create_matrix_grid(folder, number, models):
1115
  ),
1116
  )
1117
 
1118
- output = IMAGE_DIR / folder / f"gr{number}.epng"
1119
  save_named_image(grid, output)
1120
 
1121
 
@@ -1399,7 +1403,7 @@ def start_matrix(body: MatrixRequest):
1399
  matrix_pool.submit(run_matrix, body, folder, number)
1400
  return {
1401
  "status": "started",
1402
- "grid": f"{folder}/gr{number}.epng",
1403
  }
1404
 
1405
 
 
1
  import os
 
2
  import re
3
  import secrets
4
  import shutil
 
49
  from PIL.PngImagePlugin import PngInfo
50
  from pydantic import BaseModel, ConfigDict, Field
51
  from starlette.background import BackgroundTask
52
+ from workflow_api import (
53
+ ALIGN_MODEL_TYPE,
54
+ ALIGN_SCHEDULER,
55
+ GENERATION,
56
+ image_metadata,
57
+ )
58
 
59
 
60
  DATA_MOUNT = Path("/data")
 
477
  height=request.height,
478
  batch_size=1,
479
  )[0]
480
+ first_seed = GENERATION
481
  samples = run_sampler(
482
  model,
483
  first_seed,
 
506
  positive = state["encode"].encode(clip=clip, text=request.prompt)[0]
507
  negative = state["encode"].encode(clip=clip, text=request.negative)[0]
508
 
509
+ second_seed = GENERATION
510
  samples = run_sampler(
511
  model,
512
  second_seed,
 
702
  pixels=image,
703
  )[0]
704
  latent["noise_mask"] = mask
705
+ seed = GENERATION
706
  samples = run_sampler(
707
  model,
708
  seed,
 
756
  folder = (IMAGE_DIR / request.folder).resolve()
757
  if folder.parent != IMAGE_DIR.resolve():
758
  raise ValueError("Invalid matrix folder")
759
+ diagonal = folder / f"{first_id}g{GENERATION}.epng"
760
  state["vae"] = load_vae(DEFAULT_VAE)
761
 
762
  if first_id == second_id:
 
778
  )[0]
779
  samples = run_sampler(
780
  model,
781
+ GENERATION,
782
  MATRIX_FIRST_STEPS,
783
  MATRIX_FIRST_CFG,
784
  MATRIX_SAMPLER,
 
796
  release_model(first_name)
797
  return first_id
798
 
799
+ output = folder / f"{first_id}-{second_id}g{GENERATION}.epng"
800
  if output.is_file():
801
  return f"{first_id}-{second_id}"
802
 
 
820
  )[0]
821
  samples = run_sampler(
822
  model,
823
+ GENERATION,
824
  MATRIX_SECOND_STEPS,
825
  MATRIX_SECOND_CFG,
826
  MATRIX_SAMPLER,
 
1039
  with matrix_lock:
1040
  number = 1
1041
  while (
1042
+ (path / f"{number}gr{GENERATION}.epng").exists()
1043
  or (folder, number) in matrix_grids
1044
  ):
1045
  number += 1
 
1069
 
1070
  def matrix_image_path(folder, first_id, second_id):
1071
  name = (
1072
+ f"{first_id}g{GENERATION}.epng"
1073
  if first_id == second_id
1074
+ else f"{first_id}-{second_id}g{GENERATION}.epng"
1075
  )
1076
  return IMAGE_DIR / folder / name
1077
 
 
1119
  ),
1120
  )
1121
 
1122
+ output = IMAGE_DIR / folder / f"{number}gr{GENERATION}.epng"
1123
  save_named_image(grid, output)
1124
 
1125
 
 
1403
  matrix_pool.submit(run_matrix, body, folder, number)
1404
  return {
1405
  "status": "started",
1406
+ "grid": f"{folder}/{number}gr{GENERATION}.epng",
1407
  }
1408
 
1409
 
workflow_api.py CHANGED
@@ -1,12 +1,12 @@
1
  # Imports
2
  import json
3
  import os
4
- import random
5
  import sys
6
  from typing import Sequence, Mapping, Any, Union
7
 
8
  ALIGN_MODEL_TYPE = "SDXL"
9
  ALIGN_SCHEDULER = "AlignYourSteps"
 
10
 
11
 
12
  def get_value_at_index(obj: Union[Sequence, Mapping], index: int) -> Any:
@@ -802,7 +802,7 @@ def main(unload_models: bool | None = None):
802
  ksampler = KSampler()
803
  vaedecode = VAEDecode()
804
  for q in range(1):
805
- node_5_seed = prompt["5"]["inputs"]["seed"] = random.randint(1, 2**64)
806
  ksampler_5 = ksampler.sample(
807
  seed=node_5_seed,
808
  steps=16,
 
1
  # Imports
2
  import json
3
  import os
 
4
  import sys
5
  from typing import Sequence, Mapping, Any, Union
6
 
7
  ALIGN_MODEL_TYPE = "SDXL"
8
  ALIGN_SCHEDULER = "AlignYourSteps"
9
+ GENERATION = 2
10
 
11
 
12
  def get_value_at_index(obj: Union[Sequence, Mapping], index: int) -> Any:
 
802
  ksampler = KSampler()
803
  vaedecode = VAEDecode()
804
  for q in range(1):
805
+ node_5_seed = prompt["5"]["inputs"]["seed"] = GENERATION
806
  ksampler_5 = ksampler.sample(
807
  seed=node_5_seed,
808
  steps=16,