akhaliq HF Staff commited on
Commit
fb6e2ea
·
1 Parent(s): 9db0112

Fix default node layout spacing; duration=60 so xlarge 2x request stays under free-tier cap

Browse files
Files changed (2) hide show
  1. app.py +4 -4
  2. workflow.json +248 -70
app.py CHANGED
@@ -136,7 +136,7 @@ def _parse_rewrite(gen: str, fallback: str) -> str:
136
  return fallback
137
 
138
 
139
- @spaces.GPU(size="xlarge", duration=120)
140
  def enhance_prompt_t2i(prompt: str) -> str:
141
  """Rewrite a brief text-to-image request into a detailed English prompt
142
  with Qwen-Image-2.1-PE-T2I."""
@@ -157,7 +157,7 @@ def enhance_prompt_t2i(prompt: str) -> str:
157
  return _parse_rewrite(gen, prompt)
158
 
159
 
160
- @spaces.GPU(size="xlarge", duration=120)
161
  def enhance_prompt_i2i(image, instruction: str) -> str:
162
  """Rewrite an image-editing instruction against the condition image with
163
  Qwen-Image-2.1-PE-I2I."""
@@ -185,14 +185,14 @@ def enhance_prompt_i2i(image, instruction: str) -> str:
185
  return _parse_rewrite(gen, instruction)
186
 
187
 
188
- @spaces.GPU(size="xlarge", duration=150)
189
  def text_to_image(prompt: str, steps: int = 40) -> dict:
190
  """Generate an image from a text prompt with Qwen-Image 2.1."""
191
  image = pipe(prompt, num_inference_steps=_steps(steps)).images[0]
192
  return _save(image)
193
 
194
 
195
- @spaces.GPU(size="xlarge", duration=150)
196
  def edit_image(image, instruction: str, steps: int = 40) -> dict:
197
  """Edit a condition image following an instruction (image-conditioned
198
  generation with Qwen-Image 2.1)."""
 
136
  return fallback
137
 
138
 
139
+ @spaces.GPU(size="xlarge", duration=60)
140
  def enhance_prompt_t2i(prompt: str) -> str:
141
  """Rewrite a brief text-to-image request into a detailed English prompt
142
  with Qwen-Image-2.1-PE-T2I."""
 
157
  return _parse_rewrite(gen, prompt)
158
 
159
 
160
+ @spaces.GPU(size="xlarge", duration=60)
161
  def enhance_prompt_i2i(image, instruction: str) -> str:
162
  """Rewrite an image-editing instruction against the condition image with
163
  Qwen-Image-2.1-PE-I2I."""
 
185
  return _parse_rewrite(gen, instruction)
186
 
187
 
188
+ @spaces.GPU(size="xlarge", duration=60)
189
  def text_to_image(prompt: str, steps: int = 40) -> dict:
190
  """Generate an image from a text prompt with Qwen-Image 2.1."""
191
  image = pipe(prompt, num_inference_steps=_steps(steps)).images[0]
192
  return _save(image)
193
 
194
 
195
+ @spaces.GPU(size="xlarge", duration=60)
196
  def edit_image(image, instruction: str, steps: int = 40) -> dict:
197
  """Edit a condition image following an instruction (image-conditioned
198
  generation with Qwen-Image 2.1)."""
workflow.json CHANGED
@@ -8,10 +8,24 @@
8
  "role": "reference",
9
  "asset_type": "text",
10
  "x": 40,
11
- "y": 60,
12
- "data": {"out": "A capybara wearing a wizard hat, oil painting"},
13
- "inputs": [{"id": "in", "label": "Text", "type": "text"}],
14
- "outputs": [{"id": "out", "label": "Text", "type": "text"}]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  },
16
  {
17
  "id": "ref_image",
@@ -19,10 +33,22 @@
19
  "role": "reference",
20
  "asset_type": "image",
21
  "x": 40,
22
- "y": 380,
23
  "data": {},
24
- "inputs": [{"id": "in", "label": "Image", "type": "image"}],
25
- "outputs": [{"id": "out", "label": "Image", "type": "image"}]
 
 
 
 
 
 
 
 
 
 
 
 
26
  },
27
  {
28
  "id": "ref_instruction",
@@ -30,10 +56,24 @@
30
  "role": "reference",
31
  "asset_type": "text",
32
  "x": 40,
33
- "y": 640,
34
- "data": {"out": "Move it to a snowy mountain top"},
35
- "inputs": [{"id": "in", "label": "Text", "type": "text"}],
36
- "outputs": [{"id": "out", "label": "Text", "type": "text"}]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  }
38
  ],
39
  "operators": [
@@ -43,12 +83,24 @@
43
  "role": "operator",
44
  "kind": "fn",
45
  "fn": "enhance_prompt_t2i",
46
- "x": 420,
47
- "y": 60,
48
  "inputs": [
49
- {"id": "prompt", "label": "Prompt", "type": "text", "required": true}
 
 
 
 
 
50
  ],
51
- "outputs": [{"id": "out_0", "label": "Rewritten Prompt", "type": "text", "output_index": 0}]
 
 
 
 
 
 
 
52
  },
53
  {
54
  "id": "op_t2i",
@@ -56,14 +108,32 @@
56
  "role": "operator",
57
  "kind": "fn",
58
  "fn": "text_to_image",
59
- "x": 800,
60
- "y": 60,
61
- "data": {"steps": 40},
 
 
62
  "inputs": [
63
- {"id": "prompt", "label": "Prompt", "type": "text", "required": true},
64
- {"id": "steps", "label": "Steps", "type": "number"}
 
 
 
 
 
 
 
 
 
65
  ],
66
- "outputs": [{"id": "out_0", "label": "Image", "type": "image", "output_index": 0}]
 
 
 
 
 
 
 
67
  },
68
  {
69
  "id": "op_enhance_i2i",
@@ -71,13 +141,30 @@
71
  "role": "operator",
72
  "kind": "fn",
73
  "fn": "enhance_prompt_i2i",
74
- "x": 420,
75
- "y": 480,
76
  "inputs": [
77
- {"id": "image", "label": "Image", "type": "image", "required": true},
78
- {"id": "instruction", "label": "Instruction", "type": "text", "required": true}
 
 
 
 
 
 
 
 
 
 
79
  ],
80
- "outputs": [{"id": "out_0", "label": "Rewritten Instruction", "type": "text", "output_index": 0}]
 
 
 
 
 
 
 
81
  },
82
  {
83
  "id": "op_edit",
@@ -85,15 +172,38 @@
85
  "role": "operator",
86
  "kind": "fn",
87
  "fn": "edit_image",
88
- "x": 800,
89
- "y": 480,
90
- "data": {"steps": 40},
 
 
91
  "inputs": [
92
- {"id": "image", "label": "Image", "type": "image", "required": true},
93
- {"id": "instruction", "label": "Instruction", "type": "text", "required": true},
94
- {"id": "steps", "label": "Steps", "type": "number"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
  ],
96
- "outputs": [{"id": "out_0", "label": "Image", "type": "image", "output_index": 0}]
 
 
 
 
 
 
 
97
  }
98
  ],
99
  "subjects": [
@@ -102,102 +212,170 @@
102
  "label": "Rewritten Prompt",
103
  "role": "subject",
104
  "asset_type": "text",
105
- "x": 800,
106
- "y": 300,
107
- "inputs": [{"id": "in", "label": "Text", "type": "text"}],
108
- "outputs": [{"id": "out", "label": "Text", "type": "text"}]
 
 
 
 
 
 
 
 
 
 
 
 
109
  },
110
  {
111
  "id": "sub_generated",
112
  "label": "Generated Image",
113
  "role": "subject",
114
  "asset_type": "image",
115
- "x": 1180,
116
- "y": 60,
117
- "inputs": [{"id": "in", "label": "Image", "type": "image"}],
118
- "outputs": [{"id": "out", "label": "Image", "type": "image"}]
 
 
 
 
 
 
 
 
 
 
 
 
119
  },
120
  {
121
  "id": "sub_edit_prompt",
122
  "label": "Rewritten Instruction",
123
  "role": "subject",
124
  "asset_type": "text",
125
- "x": 800,
126
- "y": 720,
127
- "inputs": [{"id": "in", "label": "Text", "type": "text"}],
128
- "outputs": [{"id": "out", "label": "Text", "type": "text"}]
 
 
 
 
 
 
 
 
 
 
 
 
129
  },
130
  {
131
  "id": "sub_edited",
132
  "label": "Edited Image",
133
  "role": "subject",
134
  "asset_type": "image",
135
- "x": 1180,
136
- "y": 480,
137
- "inputs": [{"id": "in", "label": "Image", "type": "image"}],
138
- "outputs": [{"id": "out", "label": "Image", "type": "image"}]
 
 
 
 
 
 
 
 
 
 
 
 
139
  }
140
  ],
141
  "edges": [
142
  {
143
  "id": "e1",
144
- "from_node_id": "ref_prompt", "from_port_id": "out",
145
- "to_node_id": "op_enhance_t2i", "to_port_id": "prompt",
 
 
146
  "type": "text"
147
  },
148
  {
149
  "id": "e2",
150
- "from_node_id": "op_enhance_t2i", "from_port_id": "out_0",
151
- "to_node_id": "op_t2i", "to_port_id": "prompt",
 
 
152
  "type": "text"
153
  },
154
  {
155
  "id": "e3",
156
- "from_node_id": "op_enhance_t2i", "from_port_id": "out_0",
157
- "to_node_id": "sub_prompt", "to_port_id": "in",
 
 
158
  "type": "text"
159
  },
160
  {
161
  "id": "e4",
162
- "from_node_id": "op_t2i", "from_port_id": "out_0",
163
- "to_node_id": "sub_generated", "to_port_id": "in",
 
 
164
  "type": "image"
165
  },
166
  {
167
  "id": "e5",
168
- "from_node_id": "ref_image", "from_port_id": "out",
169
- "to_node_id": "op_enhance_i2i", "to_port_id": "image",
 
 
170
  "type": "image"
171
  },
172
  {
173
  "id": "e6",
174
- "from_node_id": "ref_instruction", "from_port_id": "out",
175
- "to_node_id": "op_enhance_i2i", "to_port_id": "instruction",
 
 
176
  "type": "text"
177
  },
178
  {
179
  "id": "e7",
180
- "from_node_id": "op_enhance_i2i", "from_port_id": "out_0",
181
- "to_node_id": "op_edit", "to_port_id": "instruction",
 
 
182
  "type": "text"
183
  },
184
  {
185
  "id": "e8",
186
- "from_node_id": "op_enhance_i2i", "from_port_id": "out_0",
187
- "to_node_id": "sub_edit_prompt", "to_port_id": "in",
 
 
188
  "type": "text"
189
  },
190
  {
191
  "id": "e9",
192
- "from_node_id": "ref_image", "from_port_id": "out",
193
- "to_node_id": "op_edit", "to_port_id": "image",
 
 
194
  "type": "image"
195
  },
196
  {
197
  "id": "e10",
198
- "from_node_id": "op_edit", "from_port_id": "out_0",
199
- "to_node_id": "sub_edited", "to_port_id": "in",
 
 
200
  "type": "image"
201
  }
202
  ]
203
- }
 
8
  "role": "reference",
9
  "asset_type": "text",
10
  "x": 40,
11
+ "y": 40,
12
+ "data": {
13
+ "out": "A capybara wearing a wizard hat, oil painting"
14
+ },
15
+ "inputs": [
16
+ {
17
+ "id": "in",
18
+ "label": "Text",
19
+ "type": "text"
20
+ }
21
+ ],
22
+ "outputs": [
23
+ {
24
+ "id": "out",
25
+ "label": "Text",
26
+ "type": "text"
27
+ }
28
+ ]
29
  },
30
  {
31
  "id": "ref_image",
 
33
  "role": "reference",
34
  "asset_type": "image",
35
  "x": 40,
36
+ "y": 800,
37
  "data": {},
38
+ "inputs": [
39
+ {
40
+ "id": "in",
41
+ "label": "Image",
42
+ "type": "image"
43
+ }
44
+ ],
45
+ "outputs": [
46
+ {
47
+ "id": "out",
48
+ "label": "Image",
49
+ "type": "image"
50
+ }
51
+ ]
52
  },
53
  {
54
  "id": "ref_instruction",
 
56
  "role": "reference",
57
  "asset_type": "text",
58
  "x": 40,
59
+ "y": 1150,
60
+ "data": {
61
+ "out": "Move it to a snowy mountain top"
62
+ },
63
+ "inputs": [
64
+ {
65
+ "id": "in",
66
+ "label": "Text",
67
+ "type": "text"
68
+ }
69
+ ],
70
+ "outputs": [
71
+ {
72
+ "id": "out",
73
+ "label": "Text",
74
+ "type": "text"
75
+ }
76
+ ]
77
  }
78
  ],
79
  "operators": [
 
83
  "role": "operator",
84
  "kind": "fn",
85
  "fn": "enhance_prompt_t2i",
86
+ "x": 440,
87
+ "y": 40,
88
  "inputs": [
89
+ {
90
+ "id": "prompt",
91
+ "label": "Prompt",
92
+ "type": "text",
93
+ "required": true
94
+ }
95
  ],
96
+ "outputs": [
97
+ {
98
+ "id": "out_0",
99
+ "label": "Rewritten Prompt",
100
+ "type": "text",
101
+ "output_index": 0
102
+ }
103
+ ]
104
  },
105
  {
106
  "id": "op_t2i",
 
108
  "role": "operator",
109
  "kind": "fn",
110
  "fn": "text_to_image",
111
+ "x": 840,
112
+ "y": 330,
113
+ "data": {
114
+ "steps": 40
115
+ },
116
  "inputs": [
117
+ {
118
+ "id": "prompt",
119
+ "label": "Prompt",
120
+ "type": "text",
121
+ "required": true
122
+ },
123
+ {
124
+ "id": "steps",
125
+ "label": "Steps",
126
+ "type": "number"
127
+ }
128
  ],
129
+ "outputs": [
130
+ {
131
+ "id": "out_0",
132
+ "label": "Image",
133
+ "type": "image",
134
+ "output_index": 0
135
+ }
136
+ ]
137
  },
138
  {
139
  "id": "op_enhance_i2i",
 
141
  "role": "operator",
142
  "kind": "fn",
143
  "fn": "enhance_prompt_i2i",
144
+ "x": 440,
145
+ "y": 950,
146
  "inputs": [
147
+ {
148
+ "id": "image",
149
+ "label": "Image",
150
+ "type": "image",
151
+ "required": true
152
+ },
153
+ {
154
+ "id": "instruction",
155
+ "label": "Instruction",
156
+ "type": "text",
157
+ "required": true
158
+ }
159
  ],
160
+ "outputs": [
161
+ {
162
+ "id": "out_0",
163
+ "label": "Rewritten Instruction",
164
+ "type": "text",
165
+ "output_index": 0
166
+ }
167
+ ]
168
  },
169
  {
170
  "id": "op_edit",
 
172
  "role": "operator",
173
  "kind": "fn",
174
  "fn": "edit_image",
175
+ "x": 840,
176
+ "y": 1090,
177
+ "data": {
178
+ "steps": 40
179
+ },
180
  "inputs": [
181
+ {
182
+ "id": "image",
183
+ "label": "Image",
184
+ "type": "image",
185
+ "required": true
186
+ },
187
+ {
188
+ "id": "instruction",
189
+ "label": "Instruction",
190
+ "type": "text",
191
+ "required": true
192
+ },
193
+ {
194
+ "id": "steps",
195
+ "label": "Steps",
196
+ "type": "number"
197
+ }
198
  ],
199
+ "outputs": [
200
+ {
201
+ "id": "out_0",
202
+ "label": "Image",
203
+ "type": "image",
204
+ "output_index": 0
205
+ }
206
+ ]
207
  }
208
  ],
209
  "subjects": [
 
212
  "label": "Rewritten Prompt",
213
  "role": "subject",
214
  "asset_type": "text",
215
+ "x": 840,
216
+ "y": 40,
217
+ "inputs": [
218
+ {
219
+ "id": "in",
220
+ "label": "Text",
221
+ "type": "text"
222
+ }
223
+ ],
224
+ "outputs": [
225
+ {
226
+ "id": "out",
227
+ "label": "Text",
228
+ "type": "text"
229
+ }
230
+ ]
231
  },
232
  {
233
  "id": "sub_generated",
234
  "label": "Generated Image",
235
  "role": "subject",
236
  "asset_type": "image",
237
+ "x": 1240,
238
+ "y": 330,
239
+ "inputs": [
240
+ {
241
+ "id": "in",
242
+ "label": "Image",
243
+ "type": "image"
244
+ }
245
+ ],
246
+ "outputs": [
247
+ {
248
+ "id": "out",
249
+ "label": "Image",
250
+ "type": "image"
251
+ }
252
+ ]
253
  },
254
  {
255
  "id": "sub_edit_prompt",
256
  "label": "Rewritten Instruction",
257
  "role": "subject",
258
  "asset_type": "text",
259
+ "x": 840,
260
+ "y": 800,
261
+ "inputs": [
262
+ {
263
+ "id": "in",
264
+ "label": "Text",
265
+ "type": "text"
266
+ }
267
+ ],
268
+ "outputs": [
269
+ {
270
+ "id": "out",
271
+ "label": "Text",
272
+ "type": "text"
273
+ }
274
+ ]
275
  },
276
  {
277
  "id": "sub_edited",
278
  "label": "Edited Image",
279
  "role": "subject",
280
  "asset_type": "image",
281
+ "x": 1240,
282
+ "y": 800,
283
+ "inputs": [
284
+ {
285
+ "id": "in",
286
+ "label": "Image",
287
+ "type": "image"
288
+ }
289
+ ],
290
+ "outputs": [
291
+ {
292
+ "id": "out",
293
+ "label": "Image",
294
+ "type": "image"
295
+ }
296
+ ]
297
  }
298
  ],
299
  "edges": [
300
  {
301
  "id": "e1",
302
+ "from_node_id": "ref_prompt",
303
+ "from_port_id": "out",
304
+ "to_node_id": "op_enhance_t2i",
305
+ "to_port_id": "prompt",
306
  "type": "text"
307
  },
308
  {
309
  "id": "e2",
310
+ "from_node_id": "op_enhance_t2i",
311
+ "from_port_id": "out_0",
312
+ "to_node_id": "op_t2i",
313
+ "to_port_id": "prompt",
314
  "type": "text"
315
  },
316
  {
317
  "id": "e3",
318
+ "from_node_id": "op_enhance_t2i",
319
+ "from_port_id": "out_0",
320
+ "to_node_id": "sub_prompt",
321
+ "to_port_id": "in",
322
  "type": "text"
323
  },
324
  {
325
  "id": "e4",
326
+ "from_node_id": "op_t2i",
327
+ "from_port_id": "out_0",
328
+ "to_node_id": "sub_generated",
329
+ "to_port_id": "in",
330
  "type": "image"
331
  },
332
  {
333
  "id": "e5",
334
+ "from_node_id": "ref_image",
335
+ "from_port_id": "out",
336
+ "to_node_id": "op_enhance_i2i",
337
+ "to_port_id": "image",
338
  "type": "image"
339
  },
340
  {
341
  "id": "e6",
342
+ "from_node_id": "ref_instruction",
343
+ "from_port_id": "out",
344
+ "to_node_id": "op_enhance_i2i",
345
+ "to_port_id": "instruction",
346
  "type": "text"
347
  },
348
  {
349
  "id": "e7",
350
+ "from_node_id": "op_enhance_i2i",
351
+ "from_port_id": "out_0",
352
+ "to_node_id": "op_edit",
353
+ "to_port_id": "instruction",
354
  "type": "text"
355
  },
356
  {
357
  "id": "e8",
358
+ "from_node_id": "op_enhance_i2i",
359
+ "from_port_id": "out_0",
360
+ "to_node_id": "sub_edit_prompt",
361
+ "to_port_id": "in",
362
  "type": "text"
363
  },
364
  {
365
  "id": "e9",
366
+ "from_node_id": "ref_image",
367
+ "from_port_id": "out",
368
+ "to_node_id": "op_edit",
369
+ "to_port_id": "image",
370
  "type": "image"
371
  },
372
  {
373
  "id": "e10",
374
+ "from_node_id": "op_edit",
375
+ "from_port_id": "out_0",
376
+ "to_node_id": "sub_edited",
377
+ "to_port_id": "in",
378
  "type": "image"
379
  }
380
  ]
381
+ }