Spaces:
Running on Zero
Running on Zero
Fix edit node: None-safe steps/seed, wire steps/seed refs to Edit Image
Browse files- app.py +10 -3
- workflow.json +2 -0
app.py
CHANGED
|
@@ -38,7 +38,7 @@ _loaded_steps = None
|
|
| 38 |
def _ensure_adapter(steps: int):
|
| 39 |
"""Load exactly one Pruna LoRA adapter matching the requested step count."""
|
| 40 |
global _loaded_steps
|
| 41 |
-
steps = 5 if int(steps) == 5 else 8
|
| 42 |
if _loaded_steps != steps:
|
| 43 |
pipe.unload_lora_weights()
|
| 44 |
pipe.load_lora_weights(
|
|
@@ -49,6 +49,13 @@ def _ensure_adapter(steps: int):
|
|
| 49 |
return steps
|
| 50 |
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
def _coerce_image(image):
|
| 53 |
"""Accept a PIL image, a filepath, or a Gradio/Workflow file-ref dict."""
|
| 54 |
if image is None or image == "":
|
|
@@ -79,7 +86,7 @@ def generate(prompt: str, steps: int = 8, seed: int = 42) -> dict:
|
|
| 79 |
prompt=prompt,
|
| 80 |
width=1024,
|
| 81 |
height=1024,
|
| 82 |
-
generator=torch.Generator("cuda").manual_seed(
|
| 83 |
num_inference_steps=steps,
|
| 84 |
sigmas=SIGMAS[steps],
|
| 85 |
true_cfg_scale=1.0,
|
|
@@ -95,7 +102,7 @@ def edit(image, prompt: str, steps: int = 8, seed: int = 42) -> dict:
|
|
| 95 |
out = pipe(
|
| 96 |
prompt=prompt,
|
| 97 |
image=_coerce_image(image),
|
| 98 |
-
generator=torch.Generator("cuda").manual_seed(
|
| 99 |
num_inference_steps=steps,
|
| 100 |
sigmas=SIGMAS[steps],
|
| 101 |
true_cfg_scale=1.0,
|
|
|
|
| 38 |
def _ensure_adapter(steps: int):
|
| 39 |
"""Load exactly one Pruna LoRA adapter matching the requested step count."""
|
| 40 |
global _loaded_steps
|
| 41 |
+
steps = 5 if steps is not None and int(steps) == 5 else 8
|
| 42 |
if _loaded_steps != steps:
|
| 43 |
pipe.unload_lora_weights()
|
| 44 |
pipe.load_lora_weights(
|
|
|
|
| 49 |
return steps
|
| 50 |
|
| 51 |
|
| 52 |
+
def _seed(seed) -> int:
|
| 53 |
+
try:
|
| 54 |
+
return int(seed)
|
| 55 |
+
except (TypeError, ValueError):
|
| 56 |
+
return 42
|
| 57 |
+
|
| 58 |
+
|
| 59 |
def _coerce_image(image):
|
| 60 |
"""Accept a PIL image, a filepath, or a Gradio/Workflow file-ref dict."""
|
| 61 |
if image is None or image == "":
|
|
|
|
| 86 |
prompt=prompt,
|
| 87 |
width=1024,
|
| 88 |
height=1024,
|
| 89 |
+
generator=torch.Generator("cuda").manual_seed(_seed(seed)),
|
| 90 |
num_inference_steps=steps,
|
| 91 |
sigmas=SIGMAS[steps],
|
| 92 |
true_cfg_scale=1.0,
|
|
|
|
| 102 |
out = pipe(
|
| 103 |
prompt=prompt,
|
| 104 |
image=_coerce_image(image),
|
| 105 |
+
generator=torch.Generator("cuda").manual_seed(_seed(seed)),
|
| 106 |
num_inference_steps=steps,
|
| 107 |
sigmas=SIGMAS[steps],
|
| 108 |
true_cfg_scale=1.0,
|
workflow.json
CHANGED
|
@@ -119,6 +119,8 @@
|
|
| 119 |
{"id": "e4", "from_node_id": "ref_image", "from_port_id": "out", "to_node_id": "op_edit", "to_port_id": "image", "type": "image"},
|
| 120 |
{"id": "e7", "from_node_id": "ref_edit_prompt", "from_port_id": "out", "to_node_id": "op_edit", "to_port_id": "prompt", "type": "text"},
|
| 121 |
{"id": "e5", "from_node_id": "op_generate", "from_port_id": "out_0", "to_node_id": "sub_generated", "to_port_id": "in", "type": "image"},
|
|
|
|
|
|
|
| 122 |
{"id": "e6", "from_node_id": "op_edit", "from_port_id": "out_0", "to_node_id": "sub_edited", "to_port_id": "in", "type": "image"}
|
| 123 |
]
|
| 124 |
}
|
|
|
|
| 119 |
{"id": "e4", "from_node_id": "ref_image", "from_port_id": "out", "to_node_id": "op_edit", "to_port_id": "image", "type": "image"},
|
| 120 |
{"id": "e7", "from_node_id": "ref_edit_prompt", "from_port_id": "out", "to_node_id": "op_edit", "to_port_id": "prompt", "type": "text"},
|
| 121 |
{"id": "e5", "from_node_id": "op_generate", "from_port_id": "out_0", "to_node_id": "sub_generated", "to_port_id": "in", "type": "image"},
|
| 122 |
+
{"id": "e8", "from_node_id": "ref_steps", "from_port_id": "out", "to_node_id": "op_edit", "to_port_id": "steps", "type": "number"},
|
| 123 |
+
{"id": "e9", "from_node_id": "ref_seed", "from_port_id": "out", "to_node_id": "op_edit", "to_port_id": "seed", "type": "number"},
|
| 124 |
{"id": "e6", "from_node_id": "op_edit", "from_port_id": "out_0", "to_node_id": "sub_edited", "to_port_id": "in", "type": "image"}
|
| 125 |
]
|
| 126 |
}
|