Spaces:
Running on Zero
Running on Zero
Handle None for unconnected number ports
Browse files
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=
|
| 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=
|
| 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 |
|