akhaliq HF Staff commited on
Commit
d41bbfc
·
1 Parent(s): 762c41e

Handle None for unconnected number ports

Browse files
Files changed (1) hide show
  1. app.py +8 -2
app.py CHANGED
@@ -54,10 +54,16 @@ def _save(image: Image.Image) -> str:
54
  return path
55
 
56
 
 
 
 
 
 
 
57
  @spaces.GPU(duration=120)
58
  def text_to_image(prompt: str, steps: int = 40) -> str:
59
  """Generate an image from a text prompt with Qwen-Image 2.1."""
60
- image = pipe(prompt, num_inference_steps=int(steps)).images[0]
61
  return _save(image)
62
 
63
 
@@ -65,7 +71,7 @@ def text_to_image(prompt: str, steps: int = 40) -> str:
65
  def edit_image(image, instruction: str, steps: int = 40) -> str:
66
  """Edit a condition image following an instruction (image-conditioned
67
  generation with Qwen-Image 2.1)."""
68
- edited = pipe(instruction, image=_to_pil(image), num_inference_steps=int(steps)).images[0]
69
  return _save(edited)
70
 
71
 
 
54
  return path
55
 
56
 
57
+ def _steps(value, default: int = 40) -> int:
58
+ # Unconnected number ports arrive as None; function defaults are not
59
+ # applied because the workflow executor passes arguments positionally.
60
+ return default if value is None else int(value)
61
+
62
+
63
  @spaces.GPU(duration=120)
64
  def text_to_image(prompt: str, steps: int = 40) -> str:
65
  """Generate an image from a text prompt with Qwen-Image 2.1."""
66
+ image = pipe(prompt, num_inference_steps=_steps(steps)).images[0]
67
  return _save(image)
68
 
69
 
 
71
  def edit_image(image, instruction: str, steps: int = 40) -> str:
72
  """Edit a condition image following an instruction (image-conditioned
73
  generation with Qwen-Image 2.1)."""
74
+ edited = pipe(instruction, image=_to_pil(image), num_inference_steps=_steps(steps)).images[0]
75
  return _save(edited)
76
 
77