mpasila commited on
Commit
03cd0e3
·
verified ·
1 Parent(s): 43b47b6

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +5 -4
  2. test_app.py +1 -0
app.py CHANGED
@@ -313,8 +313,8 @@ def _validate_request(mode: str, prompt: str, edit_prompt: str, primary: str | N
313
  if mode == "edit":
314
  if not primary:
315
  raise ValueError("upload a primary image for edit mode")
316
- if not (edit_prompt or "").strip():
317
- raise ValueError("enter an edit instruction")
318
 
319
 
320
  def _inject_t2i(workflow: dict[str, Any], *, prompt: str, width: int, height: int, steps: int, cfg: float, sampler: str, scheduler: str, seed: int) -> None:
@@ -421,6 +421,7 @@ def generate(
421
  staged: list[pathlib.Path] = []
422
  try:
423
  _validate_request(mode, prompt, edit_prompt, primary_image)
 
424
  if sampler not in SAMPLERS or scheduler not in SCHEDULERS:
425
  raise ValueError("unsupported sampler or scheduler")
426
  _prepare_runtime(progress)
@@ -436,9 +437,9 @@ def generate(
436
  if second_name:
437
  staged.append(INPUT / second_name)
438
  workflow = _edit_workflow(bool(second_name))
439
- _inject_edit(workflow, primary_name=primary_name, second_name=second_name, width=width, height=height, edit_prompt=edit_prompt, grounding_px=int(grounding_px), ref_boost=float(ref_boost), ref_boost_a=float(ref_boost_a), steps=int(steps), cfg=float(cfg), sampler=sampler, scheduler=scheduler, seed=effective_seed)
440
 
441
- settings = build_settings(mode=mode, prompt=prompt, edit_prompt=edit_prompt, width=width, height=height, target_megapixels=float(target_megapixels), grounding_px=int(grounding_px), ref_boost=float(ref_boost), ref_boost_a=float(ref_boost_a), steps=int(steps), cfg=float(cfg), sampler_name=sampler, scheduler=scheduler, seed=int(seed), randomize_seed=bool(randomize_seed), gen_budget=float(gen_budget), effective_seed=effective_seed)
442
  progress(0.35, desc=f"generating {mode}")
443
  result_paths = _execute_workflow(workflow)
444
  destination_dir = pathlib.Path(tempfile.mkdtemp(prefix="krea2_outputs_"))
 
313
  if mode == "edit":
314
  if not primary:
315
  raise ValueError("upload a primary image for edit mode")
316
+ if not (edit_prompt or prompt or "").strip():
317
+ raise ValueError("enter an edit instruction in the prompt or edit instruction field")
318
 
319
 
320
  def _inject_t2i(workflow: dict[str, Any], *, prompt: str, width: int, height: int, steps: int, cfg: float, sampler: str, scheduler: str, seed: int) -> None:
 
421
  staged: list[pathlib.Path] = []
422
  try:
423
  _validate_request(mode, prompt, edit_prompt, primary_image)
424
+ effective_edit_prompt = (edit_prompt or prompt or "").strip()
425
  if sampler not in SAMPLERS or scheduler not in SCHEDULERS:
426
  raise ValueError("unsupported sampler or scheduler")
427
  _prepare_runtime(progress)
 
437
  if second_name:
438
  staged.append(INPUT / second_name)
439
  workflow = _edit_workflow(bool(second_name))
440
+ _inject_edit(workflow, primary_name=primary_name, second_name=second_name, width=width, height=height, edit_prompt=effective_edit_prompt, grounding_px=int(grounding_px), ref_boost=float(ref_boost), ref_boost_a=float(ref_boost_a), steps=int(steps), cfg=float(cfg), sampler=sampler, scheduler=scheduler, seed=effective_seed)
441
 
442
+ settings = build_settings(mode=mode, prompt=prompt, edit_prompt=effective_edit_prompt, width=width, height=height, target_megapixels=float(target_megapixels), grounding_px=int(grounding_px), ref_boost=float(ref_boost), ref_boost_a=float(ref_boost_a), steps=int(steps), cfg=float(cfg), sampler_name=sampler, scheduler=scheduler, seed=int(seed), randomize_seed=bool(randomize_seed), gen_budget=float(gen_budget), effective_seed=effective_seed)
443
  progress(0.35, desc=f"generating {mode}")
444
  result_paths = _execute_workflow(workflow)
445
  destination_dir = pathlib.Path(tempfile.mkdtemp(prefix="krea2_outputs_"))
test_app.py CHANGED
@@ -54,6 +54,7 @@ class WorkflowTests(unittest.TestCase):
54
  with self.assertRaises(ValueError):
55
  app._validate_request("edit", "", "", "source.png")
56
  app._validate_request("edit", "", "change the color", "source.png")
 
57
 
58
  def test_gpu_duration_accepts_spaces_positional_callback(self):
59
  values = [
 
54
  with self.assertRaises(ValueError):
55
  app._validate_request("edit", "", "", "source.png")
56
  app._validate_request("edit", "", "change the color", "source.png")
57
+ app._validate_request("edit", "change the color", "", "source.png")
58
 
59
  def test_gpu_duration_accepts_spaces_positional_callback(self):
60
  values = [