sdiazlor commited on
Commit
3bbb0ec
·
1 Parent(s): b95ddf6

fix: update with dropdown

Browse files
Files changed (2) hide show
  1. app.py +21 -2
  2. workflow.json +5 -5
app.py CHANGED
@@ -55,6 +55,8 @@ VARIANTS = {
55
  },
56
  }
57
 
 
 
58
  VARIANT_ALIASES = {
59
  "6-steps": "6-steps",
60
  "6-step": "6-steps",
@@ -183,15 +185,32 @@ def _run_pipe(prompt: str, spec: dict, seed: int, image=None):
183
  return pipe(**kwargs).images[0]
184
 
185
 
 
 
 
 
 
 
 
 
186
  @spaces.GPU(duration=120)
187
- def generate(prompt: str, variant: str = DEFAULT_VARIANT, seed: int = 42) -> dict:
 
 
 
 
188
  """Text-to-image with P-Q-Image-2.1 (no CFG)."""
189
  spec = _ensure_variant(variant)
190
  return _to_file(_run_pipe(prompt, spec, seed))
191
 
192
 
193
  @spaces.GPU(duration=120)
194
- def edit(image, prompt: str, variant: str = DEFAULT_VARIANT, seed: int = 42) -> dict:
 
 
 
 
 
195
  """Edit an image with P-Q-Image-2.1 (no CFG)."""
196
  spec = _ensure_variant(variant)
197
  return _to_file(_run_pipe(prompt, spec, seed, image=_coerce_image(image)))
 
55
  },
56
  }
57
 
58
+ VARIANT_CHOICES = list(VARIANTS)
59
+
60
  VARIANT_ALIASES = {
61
  "6-steps": "6-steps",
62
  "6-step": "6-steps",
 
185
  return pipe(**kwargs).images[0]
186
 
187
 
188
+ def _variant_dropdown() -> gr.Dropdown:
189
+ return gr.Dropdown(
190
+ choices=VARIANT_CHOICES,
191
+ value=DEFAULT_VARIANT,
192
+ label="Variant",
193
+ )
194
+
195
+
196
  @spaces.GPU(duration=120)
197
+ def generate(
198
+ prompt: str,
199
+ variant: str = _variant_dropdown(),
200
+ seed: int = 42,
201
+ ) -> dict:
202
  """Text-to-image with P-Q-Image-2.1 (no CFG)."""
203
  spec = _ensure_variant(variant)
204
  return _to_file(_run_pipe(prompt, spec, seed))
205
 
206
 
207
  @spaces.GPU(duration=120)
208
+ def edit(
209
+ image,
210
+ prompt: str,
211
+ variant: str = _variant_dropdown(),
212
+ seed: int = 42,
213
+ ) -> dict:
214
  """Edit an image with P-Q-Image-2.1 (no CFG)."""
215
  spec = _ensure_variant(variant)
216
  return _to_file(_run_pipe(prompt, spec, seed, image=_coerce_image(image)))
workflow.json CHANGED
@@ -15,13 +15,13 @@
15
  },
16
  {
17
  "id": "ref_variant",
18
- "label": "Variant (6-steps | 6-steps-upsampled | 8-steps | 5-steps)",
19
  "role": "reference",
20
  "asset_type": "text",
21
  "x": 40,
22
  "y": 320,
23
- "inputs": [{"id": "in", "label": "Text", "type": "text"}],
24
- "outputs": [{"id": "out", "label": "Text", "type": "text"}],
25
  "data": {"out": "6-steps"}
26
  },
27
  {
@@ -68,7 +68,7 @@
68
  "y": 100,
69
  "inputs": [
70
  {"id": "prompt", "label": "Prompt", "type": "text", "required": true},
71
- {"id": "variant", "label": "Variant", "type": "text"},
72
  {"id": "seed", "label": "Seed", "type": "number"}
73
  ],
74
  "outputs": [{"id": "out_0", "label": "Image", "type": "image", "output_index": 0}]
@@ -84,7 +84,7 @@
84
  "inputs": [
85
  {"id": "image", "label": "Image", "type": "image", "required": true},
86
  {"id": "prompt", "label": "Edit Prompt", "type": "text", "required": true},
87
- {"id": "variant", "label": "Variant", "type": "text"},
88
  {"id": "seed", "label": "Seed", "type": "number"}
89
  ],
90
  "outputs": [{"id": "out_0", "label": "Edited Image", "type": "image", "output_index": 0}]
 
15
  },
16
  {
17
  "id": "ref_variant",
18
+ "label": "Variant",
19
  "role": "reference",
20
  "asset_type": "text",
21
  "x": 40,
22
  "y": 320,
23
+ "inputs": [{"id": "in", "label": "Variant", "type": "text", "choices": ["6-steps", "6-steps-upsampled", "8-steps", "5-steps"]}],
24
+ "outputs": [{"id": "out", "label": "Variant", "type": "text", "choices": ["6-steps", "6-steps-upsampled", "8-steps", "5-steps"]}],
25
  "data": {"out": "6-steps"}
26
  },
27
  {
 
68
  "y": 100,
69
  "inputs": [
70
  {"id": "prompt", "label": "Prompt", "type": "text", "required": true},
71
+ {"id": "variant", "label": "Variant", "type": "text", "choices": ["6-steps", "6-steps-upsampled", "8-steps", "5-steps"], "default_value": "6-steps"},
72
  {"id": "seed", "label": "Seed", "type": "number"}
73
  ],
74
  "outputs": [{"id": "out_0", "label": "Image", "type": "image", "output_index": 0}]
 
84
  "inputs": [
85
  {"id": "image", "label": "Image", "type": "image", "required": true},
86
  {"id": "prompt", "label": "Edit Prompt", "type": "text", "required": true},
87
+ {"id": "variant", "label": "Variant", "type": "text", "choices": ["6-steps", "6-steps-upsampled", "8-steps", "5-steps"], "default_value": "6-steps"},
88
  {"id": "seed", "label": "Seed", "type": "number"}
89
  ],
90
  "outputs": [{"id": "out_0", "label": "Edited Image", "type": "image", "output_index": 0}]