mpasila commited on
Commit
159e244
·
verified ·
1 Parent(s): 26e1295

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -8
app.py CHANGED
@@ -103,6 +103,9 @@ SCHEDULERS = ["beta", "normal", "karras", "exponential", "sgm_uniform", "simple"
103
  DEFAULT_WIDTH = 1024
104
  DEFAULT_HEIGHT = 1024
105
  DEFAULT_TARGET_MP = 1.4
 
 
 
106
  DEFAULT_GROUNDING = 768
107
  DEFAULT_REF_BOOST = 1.0
108
  DEFAULT_STEPS = 8
@@ -465,12 +468,12 @@ def _prepare_edit_image(path: str, target_megapixels: float) -> tuple[str, int,
465
  """Resize the primary source to a 64-pixel grid while preserving its AR."""
466
  with Image.open(path) as source:
467
  image = source.convert("RGB")
468
- megapixels = max(0.25, min(2.0, float(target_megapixels)))
469
  scale = (megapixels * 1_000_000 / max(1, image.width * image.height)) ** 0.5
470
  width = max(64, int(round(image.width * scale / 64) * 64))
471
  height = max(64, int(round(image.height * scale / 64) * 64))
472
- width = min(2048, width)
473
- height = min(2048, height)
474
  image = image.resize((width, height), Image.Resampling.LANCZOS)
475
  name = f"input_{uuid.uuid4().hex[:12]}.png"
476
  image.save(INPUT / name, format="PNG")
@@ -694,8 +697,8 @@ def generate(
694
  enabled_loras.append((_ensure_custom_lora(row), float(row["weight"])))
695
 
696
  if mode == "text2image":
697
- width = max(512, min(1536, int(width) // 64 * 64))
698
- height = max(512, min(1536, int(height) // 64 * 64))
699
  workflow = _t2i_workflow(base_model)
700
  else:
701
  primary_name, width, height = _prepare_edit_image(primary_image, target_megapixels)
@@ -841,10 +844,10 @@ def create_ui() -> gr.Blocks:
841
  edit_prompt = gr.Textbox(label="edit instruction", lines=3, visible=False, placeholder="recolor the jacket to matte black")
842
  with gr.Column() as t2i_resolution:
843
  with gr.Row():
844
- width = gr.Slider(512, 1536, value=DEFAULT_WIDTH, step=64, label="width")
845
- height = gr.Slider(512, 1536, value=DEFAULT_HEIGHT, step=64, label="height")
846
  with gr.Column(visible=False) as edit_controls:
847
- target_mp = gr.Slider(0.25, 2.0, value=DEFAULT_TARGET_MP, step=0.05, label="target megapixels")
848
  grounding = gr.Slider(384, 1536, value=DEFAULT_GROUNDING, step=32, label="grounding resolution")
849
  ref_boost = gr.Slider(0.0, 12.0, value=DEFAULT_REF_BOOST, step=0.1, label="primary reference strength")
850
  ref_boost_a = gr.Slider(0.0, 12.0, value=DEFAULT_REF_BOOST, step=0.1, label="second reference strength")
 
103
  DEFAULT_WIDTH = 1024
104
  DEFAULT_HEIGHT = 1024
105
  DEFAULT_TARGET_MP = 1.4
106
+ MAX_WIDTH = 2048
107
+ MAX_HEIGHT = 2048
108
+ MAX_TARGET_MP = 4.0
109
  DEFAULT_GROUNDING = 768
110
  DEFAULT_REF_BOOST = 1.0
111
  DEFAULT_STEPS = 8
 
468
  """Resize the primary source to a 64-pixel grid while preserving its AR."""
469
  with Image.open(path) as source:
470
  image = source.convert("RGB")
471
+ megapixels = max(0.25, min(MAX_TARGET_MP, float(target_megapixels)))
472
  scale = (megapixels * 1_000_000 / max(1, image.width * image.height)) ** 0.5
473
  width = max(64, int(round(image.width * scale / 64) * 64))
474
  height = max(64, int(round(image.height * scale / 64) * 64))
475
+ width = min(MAX_WIDTH, width)
476
+ height = min(MAX_HEIGHT, height)
477
  image = image.resize((width, height), Image.Resampling.LANCZOS)
478
  name = f"input_{uuid.uuid4().hex[:12]}.png"
479
  image.save(INPUT / name, format="PNG")
 
697
  enabled_loras.append((_ensure_custom_lora(row), float(row["weight"])))
698
 
699
  if mode == "text2image":
700
+ width = max(512, min(MAX_WIDTH, int(width) // 64 * 64))
701
+ height = max(512, min(MAX_HEIGHT, int(height) // 64 * 64))
702
  workflow = _t2i_workflow(base_model)
703
  else:
704
  primary_name, width, height = _prepare_edit_image(primary_image, target_megapixels)
 
844
  edit_prompt = gr.Textbox(label="edit instruction", lines=3, visible=False, placeholder="recolor the jacket to matte black")
845
  with gr.Column() as t2i_resolution:
846
  with gr.Row():
847
+ width = gr.Slider(512, MAX_WIDTH, value=DEFAULT_WIDTH, step=64, label="width")
848
+ height = gr.Slider(512, MAX_HEIGHT, value=DEFAULT_HEIGHT, step=64, label="height")
849
  with gr.Column(visible=False) as edit_controls:
850
+ target_mp = gr.Slider(0.25, MAX_TARGET_MP, value=DEFAULT_TARGET_MP, step=0.05, label="target megapixels")
851
  grounding = gr.Slider(384, 1536, value=DEFAULT_GROUNDING, step=32, label="grounding resolution")
852
  ref_boost = gr.Slider(0.0, 12.0, value=DEFAULT_REF_BOOST, step=0.1, label="primary reference strength")
853
  ref_boost_a = gr.Slider(0.0, 12.0, value=DEFAULT_REF_BOOST, step=0.1, label="second reference strength")