Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,7 @@ import requests
|
|
8 |
import io
|
9 |
import os
|
10 |
from PIL import Image
|
11 |
-
import spaces
|
12 |
import numpy as np
|
13 |
import cv2
|
14 |
from pyzxing import BarCodeReader
|
@@ -61,7 +61,7 @@ def load_models_on_launch():
|
|
61 |
loaded_controlnet = ControlNetModel.from_pretrained(
|
62 |
controlnet_path,
|
63 |
torch_dtype=torch.float16
|
64 |
-
).to("
|
65 |
|
66 |
diffusion_path = snapshot_download(DIFFUSION_MODELS["GhostMix"])
|
67 |
loaded_pipe = StableDiffusionControlNetImg2ImgPipeline.from_pretrained(
|
@@ -69,7 +69,7 @@ def load_models_on_launch():
|
|
69 |
controlnet=loaded_controlnet,
|
70 |
torch_dtype=torch.float16,
|
71 |
safety_checker=None,
|
72 |
-
).to("
|
73 |
print("Models loaded successfully!")
|
74 |
|
75 |
# Modify the load_models function to use global variables
|
@@ -174,7 +174,7 @@ def invert_displayed_image(image):
|
|
174 |
return Image.fromarray(inverted)
|
175 |
return inverted
|
176 |
|
177 |
-
|
178 |
def inference(
|
179 |
qr_code_content: str,
|
180 |
prompt: str,
|
@@ -184,7 +184,6 @@ def inference(
|
|
184 |
strength: float = 0.8,
|
185 |
seed: int = -1,
|
186 |
init_image: Image.Image | None = None,
|
187 |
-
qrcode_image: Image.Image | None = None,
|
188 |
use_qr_code_as_init_image = True,
|
189 |
sampler = "DPM++ Karras SDE",
|
190 |
bg_color: str = "white",
|
@@ -205,8 +204,8 @@ def inference(
|
|
205 |
if prompt is None or prompt == "":
|
206 |
raise gr.Error("Prompt is required")
|
207 |
|
208 |
-
if
|
209 |
-
raise gr.Error("QR Code
|
210 |
|
211 |
pipe.scheduler = SAMPLER_MAP[sampler](pipe.scheduler.config)
|
212 |
|
@@ -214,22 +213,18 @@ def inference(
|
|
214 |
seed = torch.randint(0, 2**32 - 1, (1,)).item()
|
215 |
generator = torch.manual_seed(seed)
|
216 |
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
qrcode_image = resize_for_condition_image(qrcode_image, 768)
|
230 |
-
else:
|
231 |
-
print("Using QR Code Image")
|
232 |
-
qrcode_image = resize_for_condition_image(qrcode_image, 768)
|
233 |
|
234 |
# Determine which image to use as init_image and control_image
|
235 |
if use_qr_code_as_init_image:
|
@@ -286,240 +281,133 @@ with gr.Blocks(theme='Hev832/Applio') as blocks:
|
|
286 |
"""
|
287 |

|
288 |
# 🎨 Yamamoto QR Code Art Generator
|
289 |
-
|
290 |
-
Welcome to Yamamoto's innovative QR Code Art Generator! This cutting-edge tool empowers our creative team to craft
|
291 |
-
visually stunning, on-brand QR codes that perfectly blend functionality with artistic expression.
|
292 |
-
## 🚀 How It Works:
|
293 |
-
1. **Enter Your QR Code Content**: Start by inputting the URL or text for your QR code.
|
294 |
-
2. **Craft Your Prompt**: Describe the artistic style or theme you envision for your QR code.
|
295 |
-
3. **Fine-tune with Advanced Settings**: Adjust parameters to perfect your creation (see tips below).
|
296 |
-
4. **Generate and Iterate**: Click 'Run' to create your art, then refine as needed.
|
297 |
-
## 🌟 Tips for Spectacular Results:
|
298 |
-
- **Artistic Freedom**: Set between 0.8 and 0.95 for a balance of creativity and scannability.
|
299 |
-
- **QR Code Visibility**: Aim for 0.6 to 2.0 to ensure your code is both artistic and functional.
|
300 |
-
- **Prompt Crafting**: Use vivid, specific descriptions that align with your brand identity.
|
301 |
-
- **Experimentation**: Don't hesitate to try different settings and prompts to find your perfect style!
|
302 |
-
## 🎭 Prompt Ideas to Spark Your Creativity:
|
303 |
-
- "A serene Japanese garden with cherry blossoms and a koi pond"
|
304 |
-
- "A futuristic cityscape with neon lights and flying cars"
|
305 |
-
- "An abstract painting with swirling colors and geometric shapes"
|
306 |
-
- "A vintage-style travel poster featuring iconic landmarks"
|
307 |
-
Remember, the magic lies in the details of your prompt and the fine-tuning of your settings.
|
308 |
-
Happy creating!
|
309 |
"""
|
310 |
)
|
311 |
-
with gr.Row():
|
312 |
-
with gr.Column():
|
313 |
-
qr_code_content = gr.Textbox(
|
314 |
-
label="QR Code Content",
|
315 |
-
placeholder="Enter URL or text for your QR code",
|
316 |
-
info="This is what your QR code will link to or display when scanned.",
|
317 |
-
)
|
318 |
-
|
319 |
-
prompt = gr.Textbox(
|
320 |
-
label="Artistic Prompt",
|
321 |
-
placeholder="Describe the style or theme for your QR code art",
|
322 |
-
value="A high-resolution, photo-realistic minimalist rendering of Mount Fuji, depicted as a sharp, semi-realistic silhouette of a mountain range on the horizon. The mountain evokes strength and motion with clean, crisp lines and a sense of natural flow. The scene should feature detailed snow textures, subtle highlights on the mountain ridges, and a powerful yet serene atmosphere. The rendering should emphasize the strength of the mountain with a focus on clarity and precision in both texture and light. (Sharp outlines:1.5), (Photo-realistic:1.4), (Detailed textures:1.3), (Minimalist:1.3), (Semi-realistic:1.3), (Monochrome contrast:1.2), (Crisp detail:1.2), (Evoking strength:1.2), inspired by traditional Japanese woodblock prints, nature photography, and minimalist design principles.",
|
323 |
-
info="Be specific and creative! This guides the AI in creating your unique QR code art.",
|
324 |
-
)
|
325 |
-
negative_prompt = gr.Textbox(
|
326 |
-
label="Elements to Avoid",
|
327 |
-
placeholder="Describe what you don't want in the image",
|
328 |
-
value="ugly, disfigured, low quality, blurry, nsfw, bad_pictures, (bad_prompt_version2:0.8), EasyNegative, 3d, cartoon, anime, sketches, (worst quality:2), (low quality:2), (normal quality:2), lowres, normal quality, ((monochrome)), ((grayscale)), poorly drawn, distorted, overexposed, flat shading, bad proportions, deformed, pixelated, messy details, lack of contrast, unrealistic textures, bad anatomy, rough edges, low resolution, text artifacts.",
|
329 |
-
info="List elements or styles you want to avoid in your QR code art.",
|
330 |
-
)
|
331 |
-
|
332 |
-
run_btn = gr.Button("🎨 Create Your QR Art", variant="primary")
|
333 |
-
|
334 |
-
with gr.Accordion(label="Use Your Own Image as a Reference", open=True, visible=True) as init_image_acc:
|
335 |
-
init_image = gr.Image(label="Reference Image", type="pil")
|
336 |
-
with gr.Row():
|
337 |
-
use_qr_code_as_init_image = gr.Checkbox(
|
338 |
-
label="Uncheck to use your own image for generation",
|
339 |
-
value=True,
|
340 |
-
interactive=True,
|
341 |
-
info="Allows you to use your own image for generation, otherwise a generic QR Code is created automatically as the base image"
|
342 |
-
)
|
343 |
-
invert_init_image_button = gr.Button("Invert Init Image")
|
344 |
-
|
345 |
-
with gr.Accordion(label="QR Code Image (Optional)", open=False, visible=False):
|
346 |
-
qr_code_image = gr.Image(
|
347 |
-
label="QR Code Image (Optional). Leave blank to automatically generate QR code",
|
348 |
-
type="pil",
|
349 |
-
)
|
350 |
|
351 |
-
|
352 |
-
|
353 |
-
bg_color = gr.ColorPicker(
|
354 |
-
label="Background Color",
|
355 |
-
value="#FFFFFF",
|
356 |
-
info="Choose the background color for the QR code"
|
357 |
-
)
|
358 |
-
qr_color = gr.ColorPicker(
|
359 |
-
label="QR Code Color",
|
360 |
-
value="#000000",
|
361 |
-
info="Choose the color for the QR code pattern"
|
362 |
-
)
|
363 |
-
invert_final_image = gr.Checkbox(
|
364 |
-
label="Invert Final Image",
|
365 |
-
value=False,
|
366 |
-
info="Check this to invert the colors of the final image",
|
367 |
-
visible=False,
|
368 |
-
)
|
369 |
-
with gr.Accordion("AI Model Selection", open=False):
|
370 |
-
controlnet_model_dropdown = gr.Dropdown(
|
371 |
-
choices=list(CONTROLNET_MODELS.keys()),
|
372 |
-
value="QR Code Monster",
|
373 |
-
label="ControlNet Model",
|
374 |
-
info="Select the ControlNet model for QR code generation"
|
375 |
-
)
|
376 |
-
diffusion_model_dropdown = gr.Dropdown(
|
377 |
-
choices=list(DIFFUSION_MODELS.keys()),
|
378 |
-
value="GhostMix",
|
379 |
-
label="Diffusion Model",
|
380 |
-
info="Select the main diffusion model for image generation"
|
381 |
-
)
|
382 |
-
|
383 |
-
with gr.Column():
|
384 |
-
result_image = gr.Image(label="Your Artistic QR Code")
|
385 |
-
used_seed = gr.Number(label="Seed Used", interactive=False)
|
386 |
-
|
387 |
-
with gr.Row(visible=False):
|
388 |
-
scan_button = gr.Button("Verify QR Code Works")
|
389 |
-
scan_result = gr.Textbox(label="Validation Result of QR Code", interactive=False)
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
gr.Markdown(
|
394 |
-
"""
|
395 |
-
### 🔍 Analyzing Your Creation
|
396 |
-
- Is the QR code scannable? Check with your phone camera to see if it can scan it.
|
397 |
-
- If not scannable, use the Brightness, Contrast, and Saturation sliders to optimize the QR code for scanning.
|
398 |
-
- Does the art style match your prompt? If not, try adjusting the 'Prompt Adherence'.
|
399 |
-
- Want more artistic flair? Increase the 'Artistic Freedom'.
|
400 |
-
- Need a clearer QR code? Raise the 'QR Code Visibility'.
|
401 |
-
"""
|
402 |
-
)
|
403 |
-
|
404 |
with gr.Row():
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
with gr.Accordion("Advanced Art Controls", open=True):
|
412 |
-
with gr.Row():
|
413 |
-
controlnet_conditioning_scale = gr.Slider(
|
414 |
-
minimum=0.0,
|
415 |
-
maximum=5.0,
|
416 |
-
step=0.01,
|
417 |
-
value=2,
|
418 |
-
label="QR Code Visibility in Image",
|
419 |
)
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
- **Low settings (0.0-1)**: If you choose a lower value, the QR code will blend more into the art, and it might be hard to scan with a phone. This setting is great if you want the image to look amazing, but you might lose some of the scannability. Try this if you care more about art and less about the QR code being easily recognized.
|
426 |
-
|
427 |
-
- **Medium settings (1-3)**: This is the sweet spot where the QR code remains clearly visible while still blending in with the art. You can still scan it easily with a phone, but it looks more creative. For most users, setting it around **1.1** is a great start to balance both art and function.
|
428 |
-
|
429 |
-
- **High settings (3-5.0)**: If you need to make sure that the QR code is super easy to scan, even if it means the image looks less like art and more like a regular QR code, then choose a higher value. This is ideal when functionality is the main goal, and the artistic side can take a backseat.
|
430 |
-
|
431 |
-
Start with **1.3** if you're unsure, and adjust up or down depending on whether you want the QR code to be more artistic or more functional.
|
432 |
-
"""
|
433 |
-
)
|
434 |
-
|
435 |
-
with gr.Row():
|
436 |
-
strength = gr.Slider(
|
437 |
-
minimum=0.0,
|
438 |
-
maximum=1.0,
|
439 |
-
step=0.01,
|
440 |
-
value=0.9,
|
441 |
-
label="Artistic Freedom for the AI When Generating",
|
442 |
)
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
- **Low settings (0.0-0.3)**: If you set this low, the AI will make small changes and your QR code will look more like a regular, plain QR code. This is useful if you want something that is still creative but not too wild, keeping it simple and easy to scan.
|
449 |
-
|
450 |
-
- **Medium settings (0.4-0.7)**: Here, the AI will add more artistic touches but keep the QR code recognizable. You get the best of both worlds—your QR code will have some creative flair, but it will still be easy to scan. For most cases, setting it to **0.6** is a great way to keep the code functional and artistic.
|
451 |
-
|
452 |
-
- **High settings (0.8-1.0)**: If you set this high, the AI will go all-out creative. The QR code will look amazing, but it might be difficult to scan because the art can start to take over the code. This setting is perfect if you're aiming for a highly creative piece of art and don't mind if it's a bit harder to scan. Start at **0.9** to explore creative but functional designs.
|
453 |
-
"""
|
454 |
-
)
|
455 |
-
|
456 |
-
with gr.Row():
|
457 |
-
guidance_scale = gr.Slider(
|
458 |
-
minimum=0.0,
|
459 |
-
maximum=50.0,
|
460 |
-
step=0.25,
|
461 |
-
value=7.5,
|
462 |
-
label="How Closely the AI Follows the Prompt",
|
463 |
-
|
464 |
-
)
|
465 |
-
with gr.Accordion("How Closely the AI Follows the Prompt (Click For Explanation)", open=False):
|
466 |
-
gr.Markdown(
|
467 |
-
"""
|
468 |
-
**Follow the Prompt** tells the AI how closely it should follow your description when creating the QR code art. Think of it like giving the AI instructions on how strict or flexible it can be with your design ideas:
|
469 |
-
|
470 |
-
- **Low settings (0-5)**: If you choose a lower value, the AI has more freedom to get creative on its own and may not stick too closely to your description. This is great if you want to see how the AI interprets your ideas in unexpected ways.
|
471 |
-
|
472 |
-
- **Medium settings (5-15)**: This is a good balance where the AI will mostly follow your prompt but will also add some of its own creative touches. If you want to see some surprises but still want the design to look like what you described, start at around **7.5**.
|
473 |
-
|
474 |
-
- **High settings (15+)**: If you choose a higher value, the AI will stick very closely to what you wrote in the description. This is good if you have a very specific idea and don't want the AI to change much. Just keep in mind that this might limit the AI's creativity.
|
475 |
-
|
476 |
-
Start at **7.5** for a balanced approach where the AI follows your ideas but still adds some artistic flair.
|
477 |
-
"""
|
478 |
)
|
479 |
|
480 |
-
with gr.
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
""
|
490 |
-
|
|
|
491 |
|
492 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
493 |
|
494 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
495 |
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
|
|
500 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
501 |
|
502 |
-
with gr.
|
503 |
-
|
504 |
-
minimum
|
505 |
-
maximum=
|
506 |
-
step=1,
|
507 |
-
|
508 |
-
label="Creative Seed for the Image Generation",
|
509 |
-
randomize=False,
|
510 |
-
)
|
511 |
-
with gr.Accordion("How Creative Seed Works for Generating New and Unique Images (Click For Explanation)", open=False):
|
512 |
-
gr.Markdown(
|
513 |
-
"""
|
514 |
-
**Creative Seed** controls whether the AI creates a completely new design each time or sticks to a specific design. Think of it like a recipe: with the same seed number, you get the same "recipe" for your QR code every time.
|
515 |
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
523 |
|
524 |
def scan_and_display(image):
|
525 |
if image is None:
|
@@ -581,7 +469,6 @@ with gr.Blocks(theme='Hev832/Applio') as blocks:
|
|
581 |
strength,
|
582 |
seed,
|
583 |
init_image,
|
584 |
-
qr_code_image,
|
585 |
use_qr_code_as_init_image,
|
586 |
sampler,
|
587 |
bg_color,
|
|
|
8 |
import io
|
9 |
import os
|
10 |
from PIL import Image
|
11 |
+
#import spaces
|
12 |
import numpy as np
|
13 |
import cv2
|
14 |
from pyzxing import BarCodeReader
|
|
|
61 |
loaded_controlnet = ControlNetModel.from_pretrained(
|
62 |
controlnet_path,
|
63 |
torch_dtype=torch.float16
|
64 |
+
).to("mps")
|
65 |
|
66 |
diffusion_path = snapshot_download(DIFFUSION_MODELS["GhostMix"])
|
67 |
loaded_pipe = StableDiffusionControlNetImg2ImgPipeline.from_pretrained(
|
|
|
69 |
controlnet=loaded_controlnet,
|
70 |
torch_dtype=torch.float16,
|
71 |
safety_checker=None,
|
72 |
+
).to("mps")
|
73 |
print("Models loaded successfully!")
|
74 |
|
75 |
# Modify the load_models function to use global variables
|
|
|
174 |
return Image.fromarray(inverted)
|
175 |
return inverted
|
176 |
|
177 |
+
#@spaces.GPU()
|
178 |
def inference(
|
179 |
qr_code_content: str,
|
180 |
prompt: str,
|
|
|
184 |
strength: float = 0.8,
|
185 |
seed: int = -1,
|
186 |
init_image: Image.Image | None = None,
|
|
|
187 |
use_qr_code_as_init_image = True,
|
188 |
sampler = "DPM++ Karras SDE",
|
189 |
bg_color: str = "white",
|
|
|
204 |
if prompt is None or prompt == "":
|
205 |
raise gr.Error("Prompt is required")
|
206 |
|
207 |
+
if qr_code_content == "":
|
208 |
+
raise gr.Error("QR Code Content is required")
|
209 |
|
210 |
pipe.scheduler = SAMPLER_MAP[sampler](pipe.scheduler.config)
|
211 |
|
|
|
213 |
seed = torch.randint(0, 2**32 - 1, (1,)).item()
|
214 |
generator = torch.manual_seed(seed)
|
215 |
|
216 |
+
print("Generating QR Code from content")
|
217 |
+
qr = qrcode.QRCode(
|
218 |
+
version=1,
|
219 |
+
error_correction=qrcode.constants.ERROR_CORRECT_H,
|
220 |
+
box_size=10,
|
221 |
+
border=4,
|
222 |
+
)
|
223 |
+
qr.add_data(qr_code_content)
|
224 |
+
qr.make(fit=True)
|
225 |
+
|
226 |
+
qrcode_image = qr.make_image(fill_color=qr_color, back_color=bg_color)
|
227 |
+
qrcode_image = resize_for_condition_image(qrcode_image, 768)
|
|
|
|
|
|
|
|
|
228 |
|
229 |
# Determine which image to use as init_image and control_image
|
230 |
if use_qr_code_as_init_image:
|
|
|
281 |
"""
|
282 |

|
283 |
# 🎨 Yamamoto QR Code Art Generator
|
284 |
+
Transform Your QR Codes into Brand Masterpieces
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
285 |
"""
|
286 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
287 |
|
288 |
+
with gr.Tabs():
|
289 |
+
with gr.TabItem("1. Input & Design"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
290 |
with gr.Row():
|
291 |
+
with gr.Column(scale=1):
|
292 |
+
qr_code_content = gr.Textbox(
|
293 |
+
label="QR Code Content",
|
294 |
+
placeholder="Enter URL or text for your QR code",
|
295 |
+
info="This is what your QR code will link to or display when scanned.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
296 |
)
|
297 |
+
prompt = gr.Textbox(
|
298 |
+
label="Artistic Prompt",
|
299 |
+
placeholder="Describe the style or theme for your QR code art",
|
300 |
+
value="A high-resolution, photo-realistic minimalist rendering of Mount Fuji, depicted as a sharp, semi-realistic silhouette of a mountain range on the horizon. The mountain evokes strength and motion with clean, crisp lines and a sense of natural flow. The scene should feature detailed snow textures, subtle highlights on the mountain ridges, and a powerful yet serene atmosphere. The rendering should emphasize the strength of the mountain with a focus on clarity and precision in both texture and light. (Sharp outlines:1.5), (Photo-realistic:1.4), (Detailed textures:1.3), (Minimalist:1.3), (Semi-realistic:1.3), (Monochrome contrast:1.2), (Crisp detail:1.2), (Evoking strength:1.2), inspired by traditional Japanese woodblock prints, nature photography, and minimalist design principles.",
|
301 |
+
info="Be specific and creative! This guides the AI in creating your unique QR code art.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
302 |
)
|
303 |
+
negative_prompt = gr.Textbox(
|
304 |
+
label="Elements to Avoid",
|
305 |
+
placeholder="Describe what you don't want in the image",
|
306 |
+
value="ugly, disfigured, low quality, blurry, nsfw, bad_pictures, (bad_prompt_version2:0.8), EasyNegative, 3d, cartoon, anime, sketches, (worst quality:2), (low quality:2), (normal quality:2), lowres, normal quality, ((monochrome)), ((grayscale)), poorly drawn, distorted, overexposed, flat shading, bad proportions, deformed, pixelated, messy details, lack of contrast, unrealistic textures, bad anatomy, rough edges, low resolution, text artifacts.",
|
307 |
+
info="List elements or styles you want to avoid in your QR code art.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
308 |
)
|
309 |
|
310 |
+
with gr.Column(scale=1):
|
311 |
+
with gr.Accordion("QR Code Customization", open=True):
|
312 |
+
bg_color = gr.ColorPicker(
|
313 |
+
label="Background Color",
|
314 |
+
value="#FFFFFF",
|
315 |
+
info="Choose the background color for the QR code"
|
316 |
+
)
|
317 |
+
qr_color = gr.ColorPicker(
|
318 |
+
label="QR Code Color",
|
319 |
+
value="#000000",
|
320 |
+
info="Choose the color for the QR code pattern"
|
321 |
+
)
|
322 |
|
323 |
+
with gr.Accordion("Use Your Own Image as a Reference", open=False):
|
324 |
+
init_image = gr.Image(label="Reference Image", type="pil")
|
325 |
+
use_qr_code_as_init_image = gr.Checkbox(
|
326 |
+
label="Use QR code as base image",
|
327 |
+
value=True,
|
328 |
+
interactive=True,
|
329 |
+
info="Uncheck to use your own image for generation"
|
330 |
+
)
|
331 |
+
invert_init_image_button = gr.Button("Invert Init Image")
|
332 |
+
|
333 |
+
with gr.TabItem("2. Advanced Settings"):
|
334 |
+
with gr.Row():
|
335 |
+
with gr.Column(scale=1):
|
336 |
+
with gr.Accordion("Art Generation Controls", open=True):
|
337 |
+
controlnet_conditioning_scale = gr.Slider(
|
338 |
+
minimum=0.0, maximum=5.0, step=0.01, value=2,
|
339 |
+
label="QR Code Visibility in Image",
|
340 |
+
)
|
341 |
+
strength = gr.Slider(
|
342 |
+
minimum=0.0, maximum=1.0, step=0.01, value=0.9,
|
343 |
+
label="Artistic Freedom for the AI",
|
344 |
+
)
|
345 |
+
guidance_scale = gr.Slider(
|
346 |
+
minimum=0.0, maximum=50.0, step=0.25, value=7.5,
|
347 |
+
label="How closely the AI follows the Prompt",
|
348 |
+
)
|
349 |
|
350 |
+
with gr.Accordion("Model Selection", open=True):
|
351 |
+
controlnet_model_dropdown = gr.Dropdown(
|
352 |
+
choices=list(CONTROLNET_MODELS.keys()),
|
353 |
+
value="QR Code Monster",
|
354 |
+
label="ControlNet Model",
|
355 |
+
info="Select the ControlNet model for QR code generation"
|
356 |
+
)
|
357 |
+
diffusion_model_dropdown = gr.Dropdown(
|
358 |
+
choices=list(DIFFUSION_MODELS.keys()),
|
359 |
+
value="GhostMix",
|
360 |
+
label="Diffusion Model",
|
361 |
+
info="Select the main diffusion model for image generation"
|
362 |
+
)
|
363 |
+
|
364 |
+
with gr.Column(scale=1):
|
365 |
+
with gr.Accordion("Generation Settings", open=True):
|
366 |
+
sampler = gr.Dropdown(
|
367 |
+
choices=list(SAMPLER_MAP.keys()),
|
368 |
+
value="DPM++ Karras SDE",
|
369 |
+
label="Art Style the AI uses to create the image",
|
370 |
+
)
|
371 |
+
seed = gr.Slider(
|
372 |
+
minimum=-1, maximum=9999999999, step=1, value=-1,
|
373 |
+
label="Creative Seed for the Image Generation",
|
374 |
+
randomize=False,
|
375 |
+
)
|
376 |
|
377 |
+
with gr.Accordion("Additional Options", open=False):
|
378 |
+
invert_final_image = gr.Checkbox(
|
379 |
+
label="Invert Final Image",
|
380 |
+
value=False,
|
381 |
+
info="Check this to invert the colors of the final image",
|
382 |
)
|
383 |
+
|
384 |
+
with gr.TabItem("3. Generate & Refine"):
|
385 |
+
with gr.Row():
|
386 |
+
with gr.Column(scale=1):
|
387 |
+
run_btn = gr.Button("🎨 Create Your QR Art", variant="primary")
|
388 |
+
result_image = gr.Image(label="Your Artistic QR Code")
|
389 |
+
used_seed = gr.Number(label="Seed Used", interactive=False)
|
390 |
|
391 |
+
with gr.Column(scale=1):
|
392 |
+
with gr.Accordion("Image Adjustment", open=True):
|
393 |
+
brightness = gr.Slider(minimum=0.1, maximum=2.0, step=0.1, value=1.0, label="Brightness")
|
394 |
+
contrast = gr.Slider(minimum=0.1, maximum=2.0, step=0.1, value=1.0, label="Contrast")
|
395 |
+
saturation = gr.Slider(minimum=0.1, maximum=2.0, step=0.1, value=1.0, label="Saturation")
|
396 |
+
invert_button = gr.Button("Invert Image")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
397 |
|
398 |
+
with gr.Accordion("QR Code Verification", open=True):
|
399 |
+
scan_button = gr.Button("Verify QR Code Works")
|
400 |
+
scan_result = gr.Textbox(label="Validation Result of QR Code", interactive=False)
|
401 |
+
|
402 |
+
gr.Markdown(
|
403 |
+
"""
|
404 |
+
### 🔍 Tips for Optimizing Your QR Art
|
405 |
+
- If the QR code isn't scannable, try adjusting Brightness, Contrast, and Saturation.
|
406 |
+
- For more artistic flair, increase 'Artistic Freedom' in Advanced Settings.
|
407 |
+
- To make the QR code clearer, raise 'QR Code Visibility' in Advanced Settings.
|
408 |
+
- Experiment with different prompts and settings to find your perfect style!
|
409 |
+
"""
|
410 |
+
)
|
411 |
|
412 |
def scan_and_display(image):
|
413 |
if image is None:
|
|
|
469 |
strength,
|
470 |
seed,
|
471 |
init_image,
|
|
|
472 |
use_qr_code_as_init_image,
|
473 |
sampler,
|
474 |
bg_color,
|