Oysiyl commited on
Commit
7a24597
·
1 Parent(s): b7f734a

multiple changes

Browse files
Files changed (1) hide show
  1. app.py +168 -29
app.py CHANGED
@@ -160,7 +160,7 @@ valid_models = [
160
  model_management.load_models_gpu(valid_models)
161
 
162
  @spaces.GPU(duration=20)
163
- def generate_qr_code(prompt: str, text_input: str, input_type: str = "URL"):
164
  # Only manipulate the text if it's a URL input type
165
  qr_text = text_input
166
  if input_type == "URL":
@@ -172,7 +172,7 @@ def generate_qr_code(prompt: str, text_input: str, input_type: str = "URL"):
172
  with torch.inference_mode():
173
 
174
  emptylatentimage_5 = emptylatentimage.generate(
175
- width=512, height=512, batch_size=1
176
  )
177
 
178
  cliptextencode_6 = cliptextencode.encode(
@@ -196,20 +196,24 @@ def generate_qr_code(prompt: str, text_input: str, input_type: str = "URL"):
196
  # Set protocol based on input type: None for plain text, Https for URLs
197
  qr_protocol = "None" if input_type == "Plain Text" else "Https"
198
 
199
- comfy_qr_by_module_size_15 = comfy_qr_by_module_size.generate_qr(
200
- protocol=qr_protocol,
201
- text=qr_text,
202
- module_size=12,
203
- max_image_size=512,
204
- fill_hexcolor="#000000",
205
- back_hexcolor="#FFFFFF",
206
- error_correction="Medium",
207
- border=4,
208
- module_drawer="Square",
209
- )
 
 
 
 
210
 
211
  emptylatentimage_17 = emptylatentimage.generate(
212
- width=1024, height=1024, batch_size=1
213
  )
214
 
215
  controlnetloader_19 = controlnetloader.load_controlnet(
@@ -232,7 +236,7 @@ def generate_qr_code(prompt: str, text_input: str, input_type: str = "URL"):
232
 
233
  tilepreprocessor_14 = tilepreprocessor.execute(
234
  pyrUp_iters=3,
235
- resolution=512,
236
  image=get_value_at_index(comfy_qr_by_module_size_15, 0),
237
  )
238
 
@@ -330,8 +334,9 @@ if __name__ == "__main__":
330
  - Try the examples below for inspiration
331
 
332
  ### Note:
333
- VCARD and calendar event examples aren't ready yet and will show errors if you try to use them.
334
- """)
 
335
 
336
  with gr.Row():
337
  with gr.Column():
@@ -355,6 +360,81 @@ if __name__ == "__main__":
355
  value="Enter your URL or text here... For example: https://github.com",
356
  lines=3
357
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
358
  # The generate button
359
  generate_btn = gr.Button("Generate")
360
 
@@ -365,7 +445,7 @@ if __name__ == "__main__":
365
  # When clicking the button, it will trigger the main function
366
  generate_btn.click(
367
  fn=generate_qr_code,
368
- inputs=[prompt_input, text_input, input_type],
369
  outputs=[output_image]
370
  )
371
 
@@ -374,58 +454,117 @@ if __name__ == "__main__":
374
  [
375
  "some clothes spread on ropes, realistic, great details, out in the open air sunny day realistic, great details,absence of people, Detailed and Intricate, CGI, Photoshoot,rim light, 8k, 16k, ultra detail",
376
  "https://www.google.com",
377
- "URL"
 
 
 
 
 
378
  ],
379
  [
380
  "some cards on poker tale, realistic, great details, realistic, great details,absence of people, Detailed and Intricate, CGI, Photoshoot,rim light, 8k, 16k, ultra detail",
381
  "https://store.steampowered.com",
382
- "URL"
 
 
 
 
 
383
  ],
384
  [
385
  "a beautiful sunset over mountains, photorealistic, detailed landscape, golden hour, dramatic lighting, 8k, ultra detailed",
386
  "https://github.com",
387
- "URL"
 
 
 
 
 
388
  ],
389
  [
390
  "underwater scene with coral reef and tropical fish, photorealistic, detailed, crystal clear water, sunlight rays, 8k, ultra detailed",
391
  "https://twitter.com",
392
- "URL"
 
 
 
 
 
393
  ],
394
  [
395
  "futuristic cityscape with flying cars and neon lights, cyberpunk style, detailed architecture, night scene, 8k, ultra detailed",
396
  "https://linkedin.com",
397
- "URL"
 
 
 
 
 
398
  ],
399
  [
400
  "vintage camera on wooden table, photorealistic, detailed textures, soft lighting, bokeh background, 8k, ultra detailed",
401
  "https://instagram.com",
402
- "URL"
 
 
 
 
 
403
  ],
404
  [
405
  "business card design, professional, modern, clean layout, corporate style, detailed, 8k, ultra detailed",
406
  "BEGIN:VCARD\nVERSION:3.0\nFN:John Doe\nORG:Acme Corporation\nTITLE:Software Engineer\nTEL:+1-555-123-4567\nEMAIL:[email protected]\nEND:VCARD",
407
- "Plain Text"
 
 
 
 
 
408
  ],
409
  [
410
  "wifi network symbol, modern tech, digital art, glowing blue, detailed, 8k, ultra detailed",
411
  "WIFI:T:WPA;S:MyNetwork;P:MyPassword123;;",
412
- "Plain Text"
 
 
 
 
 
413
  ],
414
  [
415
  "calendar appointment reminder, organized planner, professional office, detailed, 8k, ultra detailed",
416
  "BEGIN:VEVENT\nSUMMARY:Team Meeting\nDTSTART:20251115T140000Z\nDTEND:20251115T150000Z\nLOCATION:Conference Room A\nEND:VEVENT",
417
- "Plain Text"
 
 
 
 
 
418
  ],
419
  [
420
  "location pin on map, travel destination, scenic view, detailed cartography, 8k, ultra detailed",
421
  "geo:37.7749,-122.4194",
422
- "Plain Text"
 
 
 
 
 
423
  ]
424
  ]
425
 
426
  gr.Examples(
427
  examples=examples,
428
- inputs=[prompt_input, text_input, input_type],
 
 
 
 
 
 
 
 
 
429
  outputs=[output_image],
430
  fn=generate_qr_code,
431
  cache_examples=True
 
160
  model_management.load_models_gpu(valid_models)
161
 
162
  @spaces.GPU(duration=20)
163
+ def generate_qr_code(prompt: str, text_input: str, input_type: str = "URL", image_size: int = 512, border_size: int = 4, error_correction: str = "Medium (15%)", module_size: int = 12, module_drawer: str = "Square"):
164
  # Only manipulate the text if it's a URL input type
165
  qr_text = text_input
166
  if input_type == "URL":
 
172
  with torch.inference_mode():
173
 
174
  emptylatentimage_5 = emptylatentimage.generate(
175
+ width=image_size, height=image_size, batch_size=1
176
  )
177
 
178
  cliptextencode_6 = cliptextencode.encode(
 
196
  # Set protocol based on input type: None for plain text, Https for URLs
197
  qr_protocol = "None" if input_type == "Plain Text" else "Https"
198
 
199
+ try:
200
+ comfy_qr_by_module_size_15 = comfy_qr_by_module_size.generate_qr(
201
+ protocol=qr_protocol,
202
+ text=qr_text,
203
+ module_size=module_size,
204
+ max_image_size=image_size,
205
+ fill_hexcolor="#000000",
206
+ back_hexcolor="#FFFFFF",
207
+ error_correction=error_correction,
208
+ border=border_size,
209
+ module_drawer=module_drawer,
210
+ )
211
+ except Exception as e:
212
+ error_msg = f"Error generating QR code: {str(e)}\n\nTry with a shorter text or to increase the image size."
213
+ raise gr.Error(error_msg) from e
214
 
215
  emptylatentimage_17 = emptylatentimage.generate(
216
+ width=image_size*2, height=image_size*2, batch_size=1
217
  )
218
 
219
  controlnetloader_19 = controlnetloader.load_controlnet(
 
236
 
237
  tilepreprocessor_14 = tilepreprocessor.execute(
238
  pyrUp_iters=3,
239
+ resolution=image_size,
240
  image=get_value_at_index(comfy_qr_by_module_size_15, 0),
241
  )
242
 
 
334
  - Try the examples below for inspiration
335
 
336
  ### Note:
337
+ Feel free to share your suggestions or feedback on how to improve the app! Thanks!
338
+
339
+ """)
340
 
341
  with gr.Row():
342
  with gr.Column():
 
360
  value="Enter your URL or text here... For example: https://github.com",
361
  lines=3
362
  )
363
+
364
+ with gr.Accordion("Advanced Settings", open=False):
365
+ # Add image size slider
366
+ image_size = gr.Slider(
367
+ minimum=512,
368
+ maximum=1024,
369
+ step=64,
370
+ value=512,
371
+ label="Image Size",
372
+ info="Base size of the generated image. Final output will be 2x this size (e.g., 512 → 1024) due to the two-step enhancement process. Higher values use more VRAM and take longer to process."
373
+ )
374
+
375
+ # Add border size slider
376
+ border_size = gr.Slider(
377
+ minimum=0,
378
+ maximum=8,
379
+ step=1,
380
+ value=4,
381
+ label="QR Code Border Size",
382
+ info="Number of modules (squares) to use as border around the QR code. Higher values add more whitespace."
383
+ )
384
+
385
+ # Add error correction dropdown
386
+ error_correction = gr.Dropdown(
387
+ choices=["Low (7%)", "Medium (15%)", "Quartile (25%)", "High (30%)"],
388
+ value="Medium (15%)",
389
+ label="Error Correction Level",
390
+ info="Higher error correction makes the QR code more scannable when damaged or obscured, but increases its size and complexity. Medium (15%) is a good starting point for most uses."
391
+ )
392
+
393
+ # Add module size slider
394
+ module_size = gr.Slider(
395
+ minimum=4,
396
+ maximum=16,
397
+ step=1,
398
+ value=12,
399
+ label="QR Module Size",
400
+ info="Pixel width of the smallest QR code unit. Larger values improve readability but require a larger image size. 12 is a good starting point."
401
+ )
402
+
403
+ # Add module drawer dropdown with style examples
404
+ module_drawer = gr.Dropdown(
405
+ choices=["Square", "Gapped Square", "Circle", "Rounded", "Vertical bars", "Horizontal bars"],
406
+ value="Square",
407
+ label="QR Code Style",
408
+ info="Select the style of the QR code modules (squares). See examples below. Different styles can give your QR code a unique look while maintaining scannability."
409
+ )
410
+
411
+ # Add style examples with labels
412
+ gr.Markdown("### Style Examples:")
413
+
414
+ # First row of examples
415
+ with gr.Row():
416
+ with gr.Column(scale=1, min_width=0):
417
+ gr.Markdown("**Square**", show_label=False)
418
+ gr.Image("custom_nodes/ComfyQR/img/square.png", width=100, show_label=False, show_download_button=False)
419
+ with gr.Column(scale=1, min_width=0):
420
+ gr.Markdown("**Gapped Square**", show_label=False)
421
+ gr.Image("custom_nodes/ComfyQR/img/gapped_square.png", width=100, show_label=False, show_download_button=False)
422
+ with gr.Column(scale=1, min_width=0):
423
+ gr.Markdown("**Circle**", show_label=False)
424
+ gr.Image("custom_nodes/ComfyQR/img/circle.png", width=100, show_label=False, show_download_button=False)
425
+
426
+ # Second row of examples
427
+ with gr.Row():
428
+ with gr.Column(scale=1, min_width=0):
429
+ gr.Markdown("**Rounded**", show_label=False)
430
+ gr.Image("custom_nodes/ComfyQR/img/rounded.png", width=100, show_label=False, show_download_button=False)
431
+ with gr.Column(scale=1, min_width=0):
432
+ gr.Markdown("**Vertical Bars**", show_label=False)
433
+ gr.Image("custom_nodes/ComfyQR/img/vertical-bars.png", width=100, show_label=False, show_download_button=False)
434
+ with gr.Column(scale=1, min_width=0):
435
+ gr.Markdown("**Horizontal Bars**", show_label=False)
436
+ gr.Image("custom_nodes/ComfyQR/img/horizontal-bars.png", width=100, show_label=False, show_download_button=False)
437
+
438
  # The generate button
439
  generate_btn = gr.Button("Generate")
440
 
 
445
  # When clicking the button, it will trigger the main function
446
  generate_btn.click(
447
  fn=generate_qr_code,
448
+ inputs=[prompt_input, text_input, input_type, image_size, border_size, error_correction, module_size, module_drawer],
449
  outputs=[output_image]
450
  )
451
 
 
454
  [
455
  "some clothes spread on ropes, realistic, great details, out in the open air sunny day realistic, great details,absence of people, Detailed and Intricate, CGI, Photoshoot,rim light, 8k, 16k, ultra detail",
456
  "https://www.google.com",
457
+ "URL",
458
+ 512,
459
+ 4,
460
+ "Medium (15%)",
461
+ 12,
462
+ "Square"
463
  ],
464
  [
465
  "some cards on poker tale, realistic, great details, realistic, great details,absence of people, Detailed and Intricate, CGI, Photoshoot,rim light, 8k, 16k, ultra detail",
466
  "https://store.steampowered.com",
467
+ "URL",
468
+ 512,
469
+ 4,
470
+ "Medium (15%)",
471
+ 12,
472
+ "Square"
473
  ],
474
  [
475
  "a beautiful sunset over mountains, photorealistic, detailed landscape, golden hour, dramatic lighting, 8k, ultra detailed",
476
  "https://github.com",
477
+ "URL",
478
+ 512,
479
+ 4,
480
+ "Medium (15%)",
481
+ 12,
482
+ "Square"
483
  ],
484
  [
485
  "underwater scene with coral reef and tropical fish, photorealistic, detailed, crystal clear water, sunlight rays, 8k, ultra detailed",
486
  "https://twitter.com",
487
+ "URL",
488
+ 512,
489
+ 4,
490
+ "Medium (15%)",
491
+ 12,
492
+ "Square"
493
  ],
494
  [
495
  "futuristic cityscape with flying cars and neon lights, cyberpunk style, detailed architecture, night scene, 8k, ultra detailed",
496
  "https://linkedin.com",
497
+ "URL",
498
+ 512,
499
+ 4,
500
+ "Medium (15%)",
501
+ 12,
502
+ "Square"
503
  ],
504
  [
505
  "vintage camera on wooden table, photorealistic, detailed textures, soft lighting, bokeh background, 8k, ultra detailed",
506
  "https://instagram.com",
507
+ "URL",
508
+ 512,
509
+ 4,
510
+ "Medium (15%)",
511
+ 12,
512
+ "Square"
513
  ],
514
  [
515
  "business card design, professional, modern, clean layout, corporate style, detailed, 8k, ultra detailed",
516
  "BEGIN:VCARD\nVERSION:3.0\nFN:John Doe\nORG:Acme Corporation\nTITLE:Software Engineer\nTEL:+1-555-123-4567\nEMAIL:[email protected]\nEND:VCARD",
517
+ "Plain Text",
518
+ 704,
519
+ 4,
520
+ "Medium (15%)",
521
+ 12,
522
+ "Square"
523
  ],
524
  [
525
  "wifi network symbol, modern tech, digital art, glowing blue, detailed, 8k, ultra detailed",
526
  "WIFI:T:WPA;S:MyNetwork;P:MyPassword123;;",
527
+ "Plain Text",
528
+ 512,
529
+ 4,
530
+ "Medium (15%)",
531
+ 12,
532
+ "Square"
533
  ],
534
  [
535
  "calendar appointment reminder, organized planner, professional office, detailed, 8k, ultra detailed",
536
  "BEGIN:VEVENT\nSUMMARY:Team Meeting\nDTSTART:20251115T140000Z\nDTEND:20251115T150000Z\nLOCATION:Conference Room A\nEND:VEVENT",
537
+ "Plain Text",
538
+ 512,
539
+ 4,
540
+ "Medium (15%)",
541
+ 12,
542
+ "Square"
543
  ],
544
  [
545
  "location pin on map, travel destination, scenic view, detailed cartography, 8k, ultra detailed",
546
  "geo:37.7749,-122.4194",
547
+ "Plain Text",
548
+ 512,
549
+ 4,
550
+ "Medium (15%)",
551
+ 12,
552
+ "Square"
553
  ]
554
  ]
555
 
556
  gr.Examples(
557
  examples=examples,
558
+ inputs=[
559
+ prompt_input,
560
+ text_input,
561
+ input_type,
562
+ image_size,
563
+ border_size,
564
+ error_correction,
565
+ module_size,
566
+ module_drawer
567
+ ],
568
  outputs=[output_image],
569
  fn=generate_qr_code,
570
  cache_examples=True