Oysiyl commited on
Commit
f9eb2b6
·
1 Parent(s): ee35bee

show intermediate steps of a pipeline

Browse files
Files changed (1) hide show
  1. app.py +21 -10
app.py CHANGED
@@ -213,7 +213,16 @@ def generate_qr_code(prompt: str, text_input: str, input_type: str = "URL", imag
213
  f"Error generating QR code: {str(e)}\n"
214
  "Try with a shorter text, increase the image size, or decrease the border size, module size, and error correction level under Advanced Settings."
215
  )
216
- return None, error_msg
 
 
 
 
 
 
 
 
 
217
 
218
  emptylatentimage_17 = emptylatentimage.generate(
219
  width=image_size*2, height=image_size*2, batch_size=1
@@ -272,9 +281,12 @@ def generate_qr_code(prompt: str, text_input: str, input_type: str = "URL", imag
272
  vae=get_value_at_index(checkpointloadersimple_4, 2),
273
  )
274
 
275
- # saveimage_9 = saveimage.save_images(
276
- # filename_prefix="qr-new", images=get_value_at_index(vaedecode_8, 0)
277
- # )
 
 
 
278
 
279
  controlnetapplyadvanced_20 = controlnetapplyadvanced.apply_controlnet(
280
  strength=1,
@@ -310,14 +322,12 @@ def generate_qr_code(prompt: str, text_input: str, input_type: str = "URL", imag
310
  # images=get_value_at_index(vaedecode_21, 0),
311
  # )
312
 
313
- # Convert torch tensor to PIL Image
314
  image_tensor = get_value_at_index(vaedecode_21, 0)
315
- # Convert from [0,1] to [0,255] range and to uint8
316
  image_np = (image_tensor.cpu().numpy() * 255).astype(np.uint8)
317
- # Remove batch dimension and convert to PIL Image
318
- image_np = image_np[0] # Shape will be (1024, 1024, 3)
319
  pil_image = Image.fromarray(image_np)
320
- return pil_image, "No errors, all good!"
321
 
322
 
323
  if __name__ == "__main__":
@@ -355,7 +365,8 @@ if __name__ == "__main__":
355
  prompt_input = gr.Textbox(
356
  label="Prompt",
357
  placeholder="Describe the image you want to generate (check examples below for inspiration)",
358
- value="Enter your prompt here... For example: 'a beautiful sunset over mountains, photorealistic, detailed landscape'"
 
359
  )
360
  text_input = gr.Textbox(
361
  label="QR Code Content",
 
213
  f"Error generating QR code: {str(e)}\n"
214
  "Try with a shorter text, increase the image size, or decrease the border size, module size, and error correction level under Advanced Settings."
215
  )
216
+ # Stream a single error message
217
+ yield None, error_msg
218
+ return
219
+
220
+ # 1) Yield the base QR image as the first intermediate result
221
+ base_qr_tensor = get_value_at_index(comfy_qr_by_module_size_15, 0)
222
+ base_qr_np = (base_qr_tensor.cpu().numpy() * 255).astype(np.uint8)
223
+ base_qr_np = base_qr_np[0]
224
+ base_qr_pil = Image.fromarray(base_qr_np)
225
+ yield base_qr_pil, "Generated base QR pattern… enhancing with AI (step 1/3)"
226
 
227
  emptylatentimage_17 = emptylatentimage.generate(
228
  width=image_size*2, height=image_size*2, batch_size=1
 
281
  vae=get_value_at_index(checkpointloadersimple_4, 2),
282
  )
283
 
284
+ # 2) Yield the first decoded image as a second intermediate result
285
+ mid_tensor = get_value_at_index(vaedecode_8, 0)
286
+ mid_np = (mid_tensor.cpu().numpy() * 255).astype(np.uint8)
287
+ mid_np = mid_np[0]
288
+ mid_pil = Image.fromarray(mid_np)
289
+ yield mid_pil, "First enhancement pass complete (step 2/3)… refining details"
290
 
291
  controlnetapplyadvanced_20 = controlnetapplyadvanced.apply_controlnet(
292
  strength=1,
 
322
  # images=get_value_at_index(vaedecode_21, 0),
323
  # )
324
 
325
+ # 3) Yield the final enhanced image
326
  image_tensor = get_value_at_index(vaedecode_21, 0)
 
327
  image_np = (image_tensor.cpu().numpy() * 255).astype(np.uint8)
328
+ image_np = image_np[0]
 
329
  pil_image = Image.fromarray(image_np)
330
+ yield pil_image, "No errors, all good! Final QR art generated."
331
 
332
 
333
  if __name__ == "__main__":
 
365
  prompt_input = gr.Textbox(
366
  label="Prompt",
367
  placeholder="Describe the image you want to generate (check examples below for inspiration)",
368
+ value="Enter your prompt here... For example: 'a beautiful sunset over mountains, photorealistic, detailed landscape'",
369
+ lines=3
370
  )
371
  text_input = gr.Textbox(
372
  label="QR Code Content",