File size: 28,047 Bytes
1f7d355 eb887b5 6d9a769 ec1d587 3960520 2b46bb5 a47b847 6d9a769 f550b6d 5fa2101 6d9a769 2b46bb5 6d9a769 f550b6d 2b46bb5 6d9a769 5fa2101 63d2006 f550b6d 63d2006 6d9a769 63d2006 f550b6d 63d2006 d6ceac1 63d2006 f550b6d 63d2006 d6ceac1 63d2006 f550b6d 63d2006 3960520 63d2006 5fa2101 63d2006 3960520 63d2006 d6ceac1 3960520 5fa2101 3960520 5fa2101 3960520 5fa2101 3960520 5fa2101 3960520 63d2006 3960520 5fa2101 3960520 5fa2101 3960520 5fa2101 3960520 5fa2101 3960520 5fa2101 3960520 5fa2101 3960520 d6ceac1 2b46bb5 eb887b5 c0196db ec1d587 c0196db af59de2 5fa2101 ec1d587 660d6b4 af59de2 5fa2101 eb887b5 af59de2 eb887b5 af59de2 eb887b5 af59de2 5fa2101 af59de2 eb887b5 3960520 5fa2101 aa67d14 5fa2101 aa67d14 5fa2101 aa67d14 5fa2101 af59de2 5fa2101 3960520 5fa2101 af59de2 5fa2101 af59de2 5fa2101 af59de2 5fa2101 af59de2 5fa2101 af59de2 5fa2101 af59de2 5fa2101 af59de2 5fa2101 af59de2 5fa2101 af59de2 5fa2101 af59de2 5fa2101 af59de2 5fa2101 af59de2 5fa2101 af59de2 5fa2101 af59de2 5fa2101 af59de2 f550b6d af59de2 5fa2101 af59de2 3960520 e603970 5fa2101 ec1d587 e603970 5fa2101 af59de2 ec1d587 af59de2 5fa2101 af59de2 5fa2101 af59de2 5fa2101 af59de2 5fa2101 af59de2 5fa2101 af59de2 5fa2101 af59de2 5fa2101 af59de2 5fa2101 af59de2 5fa2101 af59de2 c622495 5fa2101 c622495 af59de2 c622495 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 | import gradio as gr
import qrcode
import random
import os
from datetime import datetime
from PIL import Image, ImageDraw
from math import cos, sin, radians
def create_border_decoration(qr_image, decoration_style="Flowers"):
# Convert QR image to RGB mode first
qr_image = qr_image.convert('RGB')
# Get the size of the QR code image
width, height = qr_image.size
# ν¨λ©μ λ μκ² μ‘°μ
padding = 20
new_width = width + (padding * 2)
new_height = height + (padding * 2)
# Create new image with white background
decorated_image = Image.new('RGB', (new_width, new_height), 'white')
# Paste QR code in center
decorated_image.paste(qr_image, (padding, padding))
# Get draw object
draw = ImageDraw.Draw(decorated_image)
# μ₯μ ν¬κΈ° μ€μ
deco_size = 8
gap = deco_size * 1.5
# ν
λ리λ₯Ό λ°λΌ μ λ€μ μμΉ κ³μ°
border_points = []
# μλ¨ ν
λ리
for x in range(padding//2, new_width - padding//2, int(gap)):
border_points.append((x, padding//2))
# μ°μΈ‘ ν
λ리
for y in range(padding//2, new_height - padding//2, int(gap)):
border_points.append((new_width - padding//2, y))
# νλ¨ ν
λ리
for x in range(new_width - padding//2, padding//2, -int(gap)):
border_points.append((x, new_height - padding//2))
# μ’μΈ‘ ν
λ리
for y in range(new_height - padding//2, padding//2, -int(gap)):
border_points.append((padding//2, y))
# κ° μ€νμΌμ λ°λ₯Έ μ₯μ 그리기
for x, y in border_points:
if decoration_style == "Flowers":
for angle in range(0, 360, 45):
x1 = x + deco_size * cos(radians(angle))
y1 = y + deco_size * sin(radians(angle))
draw.ellipse([x1-4, y1-4, x1+4, y1+4], fill='pink')
draw.ellipse([x-3, y-3, x+3, y+3], fill='yellow')
elif decoration_style == "Hearts":
heart_size = 6
draw.ellipse([x-heart_size, y-heart_size, x, y], fill='red')
draw.ellipse([x, y-heart_size, x+heart_size, y], fill='red')
draw.polygon([(x-heart_size, y), (x+heart_size, y), (x, y+heart_size)], fill='red')
elif decoration_style == "Waves":
wave_size = 10
draw.arc([x-wave_size, y-wave_size//2, x+wave_size, y+wave_size//2],
0, 180, fill='lightblue', width=2)
draw.arc([x-wave_size, y, x+wave_size, y+wave_size],
0, 180, fill='blue', width=2)
elif decoration_style == "Leaves":
leaf_size = 8
draw.ellipse([x-leaf_size, y-leaf_size//2, x+leaf_size, y+leaf_size//2],
fill='lightgreen')
draw.ellipse([x-leaf_size//2, y-leaf_size, x+leaf_size//2, y+leaf_size],
fill='darkgreen')
elif decoration_style == "Stars":
star_size = 6
points = []
for i in range(5):
angle = i * 72
x1 = x + star_size * cos(radians(angle))
y1 = y + star_size * sin(radians(angle))
points.append((x1, y1))
x2 = x + (star_size/2) * cos(radians(angle + 36))
y2 = y + (star_size/2) * sin(radians(angle + 36))
points.append((x2, y2))
draw.polygon(points, fill='gold')
elif decoration_style == "Chains":
chain_size = 8
draw.ellipse([x-chain_size, y-chain_size//2, x+chain_size, y+chain_size//2],
outline='gray', width=2)
elif decoration_style == "Bubbles":
bubble_sizes = [6, 4, 2]
for size in bubble_sizes:
draw.ellipse([x-size, y-size, x+size, y+size],
outline='skyblue', width=1)
elif decoration_style == "Vines":
vine_size = 10
draw.arc([x-vine_size, y-vine_size, x+vine_size, y+vine_size],
0, 180, fill='green', width=2)
draw.ellipse([x-3, y-3, x+3, y+3], fill='lightgreen')
elif decoration_style == "Diamonds":
diamond_size = 6
points = [
(x, y-diamond_size),
(x+diamond_size, y),
(x, y+diamond_size),
(x-diamond_size, y)
]
draw.polygon(points, outline='purple', width=1)
elif decoration_style == "Lace":
lace_size = 8
draw.arc([x-lace_size, y-lace_size, x+lace_size, y+lace_size],
0, 180, fill='gray', width=1)
draw.arc([x-lace_size//2, y-lace_size//2, x+lace_size//2, y+lace_size//2],
180, 360, fill='gray', width=1)
return decorated_image
def rgba_to_rgb(rgba_color):
"""Convert RGBA color string to RGB hex color"""
if rgba_color.startswith('rgba'):
values = rgba_color.strip('rgba()').split(',')
r = int(float(values[0]))
g = int(float(values[1]))
b = int(float(values[2]))
return f'#{r:02x}{g:02x}{b:02x}'
return rgba_color
def create_qr(content, qr_type, fill_color, back_color, box_size, border_size, error_correction, border_decoration="No Decoration"):
# Convert RGBA colors to RGB
fill_color = rgba_to_rgb(fill_color)
back_color = rgba_to_rgb(back_color)
# QR μ½λ λ°μ΄ν° ν¬λ§·ν
formatted_data = format_data(content, qr_type)
# μλ¬ μμ λ 벨 μ€μ
error_levels = {
"Low (7%)": qrcode.constants.ERROR_CORRECT_L,
"Medium (15%)": qrcode.constants.ERROR_CORRECT_M,
"Quartile (25%)": qrcode.constants.ERROR_CORRECT_Q,
"High (30%)": qrcode.constants.ERROR_CORRECT_H
}
# QR μ½λ μμ±
qr = qrcode.QRCode(
version=1,
error_correction=error_levels[error_correction],
box_size=box_size,
border=border_size,
)
qr.add_data(formatted_data)
qr.make(fit=True)
# QR μ΄λ―Έμ§ μμ±
qr_img = qr.make_image(fill_color=fill_color, back_color=back_color)
# Add border decoration if specified
if border_decoration != "No Decoration":
qr_img = create_border_decoration(qr_img, border_decoration)
# νμΌ μ μ₯
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
random_id = random.randint(1000, 9999)
filename = f"qrfile/qr_{timestamp}_{random_id}.png"
os.makedirs("qrfile", exist_ok=True)
qr_img.save(filename)
cleanup_old_files("qrfile/", max_files=100)
# μ 보 λ‘κ·Έ μμ±
info_log = f"""β
QR CODE GENERATED!
{'=' * 50}
π QR Code Info:
β’ Type: {qr_type}
β’ Content: {content[:40]}{'...' if len(content) > 40 else ''}
{'=' * 50}
π¨ Style Settings:
β’ QR Color: {fill_color}
β’ Background: {back_color}
β’ Size: {box_size}
β’ Border: {border_size}
β’ Decoration: {border_decoration}
{'=' * 50}
π§ Technical:
β’ Error Correction: {error_correction}
β’ Formatted Data: {formatted_data[:50]}{'...' if len(formatted_data) > 50 else ''}
{'=' * 50}
πΎ Ready to download!"""
return filename, formatted_data, info_log
def format_data(content, qr_type):
if not content:
return ""
format_rules = {
"URL": lambda x: f"https://{x}" if not x.startswith(('http://', 'https://')) else x,
"Email": lambda x: f"mailto:{x}",
"Phone": lambda x: f"tel:{x}",
"SMS": lambda x: f"sms:{x}",
"WhatsApp": lambda x: f"whatsapp://send?text={x}",
"Location": lambda x: f"geo:{x}",
"Wi-Fi": lambda x: f"WIFI:S:{x};;",
"Text": lambda x: x,
"vCard": lambda x: f"BEGIN:VCARD\nVERSION:3.0\n{x}\nEND:VCARD"
}
return format_rules[qr_type](content.strip())
def cleanup_old_files(directory, max_files):
files = [f for f in os.listdir(directory) if f.endswith('.png')]
if len(files) > max_files:
files.sort(key=lambda x: os.path.getctime(os.path.join(directory, x)))
for f in files[:-max_files]:
try:
os.remove(os.path.join(directory, f))
except:
continue
def format_example_text(qr_type):
examples = {
"URL": "β’ Direct URL: https://example.com\nβ’ Without https: example.com",
"Email": "β’ Basic: example@email.com\nβ’ With subject: example@email.com?subject=Hello",
"Phone": "β’ International: +1234567890\nβ’ Local: 01012345678",
"SMS": "β’ Basic: +1234567890\nβ’ With message: +1234567890?body=Hello",
"WhatsApp": "β’ Message: Hello World!\nβ’ With number: +1234567890:Hello",
"Location": "β’ Coordinates: 37.7749,-122.4194\nβ’ With zoom: 37.7749,-122.4194,15z",
"Wi-Fi": "β’ Network name only: MyWiFiNetwork\nβ’ With password: WIFI:S:MyNetwork;P:password;;",
"Text": "β’ Simple text: Hello World!\nβ’ Multiple lines: Line 1\\nLine 2",
"vCard": "β’ Basic:\nFN:John Doe\nTEL:+1234567890\nEMAIL:john@example.com"
}
return examples.get(qr_type, "Enter your content here...")
# ============================================
# π¨ Comic Classic Theme - Toon Playground
# ============================================
css = """
/* ===== π¨ Google Fonts Import ===== */
@import url('https://fonts.googleapis.com/css2?family=Bangers&family=Comic+Neue:wght@400;700&display=swap');
/* ===== π¨ Comic Classic λ°°κ²½ - λΉν°μ§ νμ΄νΌ + λνΈ ν¨ν΄ ===== */
.gradio-container {
background-color: #FEF9C3 !important;
background-image:
radial-gradient(#1F2937 1px, transparent 1px) !important;
background-size: 20px 20px !important;
min-height: 100vh !important;
font-family: 'Comic Neue', cursive, sans-serif !important;
}
/* ===== νκΉ
νμ΄μ€ μλ¨ μμ μ¨κΉ ===== */
.huggingface-space-header,
#space-header,
.space-header,
[class*="space-header"],
.svelte-1ed2p3z,
.space-header-badge,
.header-badge,
[data-testid="space-header"],
.svelte-kqij2n,
.svelte-1ax1toq,
.embed-container > div:first-child {
display: none !important;
visibility: hidden !important;
height: 0 !important;
width: 0 !important;
overflow: hidden !important;
opacity: 0 !important;
pointer-events: none !important;
}
/* ===== Footer μμ μ¨κΉ ===== */
footer,
.footer,
.gradio-container footer,
.built-with,
[class*="footer"],
.gradio-footer,
.main-footer,
div[class*="footer"],
.show-api,
.built-with-gradio,
a[href*="gradio.app"],
a[href*="huggingface.co/spaces"] {
display: none !important;
visibility: hidden !important;
height: 0 !important;
padding: 0 !important;
margin: 0 !important;
}
/* ===== λ©μΈ 컨ν
μ΄λ ===== */
#col-container {
max-width: 1200px;
margin: 0 auto;
}
/* ===== π¨ ν€λ νμ΄ν - μ½λ―Ή μ€νμΌ ===== */
.header-text h1 {
font-family: 'Bangers', cursive !important;
color: #1F2937 !important;
font-size: 3.5rem !important;
font-weight: 400 !important;
text-align: center !important;
margin-bottom: 0.5rem !important;
text-shadow:
4px 4px 0px #FACC15,
6px 6px 0px #1F2937 !important;
letter-spacing: 3px !important;
-webkit-text-stroke: 2px #1F2937 !important;
}
/* ===== π¨ μλΈνμ΄ν ===== */
.subtitle {
text-align: center !important;
font-family: 'Comic Neue', cursive !important;
font-size: 1.2rem !important;
color: #1F2937 !important;
margin-bottom: 1.5rem !important;
font-weight: 700 !important;
}
/* ===== π¨ μΉ΄λ/ν¨λ - λ§ν νλ μ μ€νμΌ ===== */
.gr-panel,
.gr-box,
.gr-form,
.block,
.gr-group {
background: #FFFFFF !important;
border: 3px solid #1F2937 !important;
border-radius: 8px !important;
box-shadow: 6px 6px 0px #1F2937 !important;
transition: all 0.2s ease !important;
}
.gr-panel:hover,
.block:hover {
transform: translate(-2px, -2px) !important;
box-shadow: 8px 8px 0px #1F2937 !important;
}
/* ===== π¨ μ
λ ₯ νλ (Textbox) ===== */
textarea,
input[type="text"],
input[type="number"] {
background: #FFFFFF !important;
border: 3px solid #1F2937 !important;
border-radius: 8px !important;
color: #1F2937 !important;
font-family: 'Comic Neue', cursive !important;
font-size: 1rem !important;
font-weight: 700 !important;
transition: all 0.2s ease !important;
}
textarea:focus,
input[type="text"]:focus,
input[type="number"]:focus {
border-color: #3B82F6 !important;
box-shadow: 4px 4px 0px #3B82F6 !important;
outline: none !important;
}
textarea::placeholder {
color: #9CA3AF !important;
font-weight: 400 !important;
}
/* ===== π¨ λλ‘λ€μ΄ μ€νμΌ ===== */
.gr-dropdown {
background: #FFFFFF !important;
border: 3px solid #1F2937 !important;
border-radius: 8px !important;
box-shadow: 3px 3px 0px #1F2937 !important;
}
.gr-dropdown > div {
background: #FFFFFF !important;
border: none !important;
}
.gr-dropdown input {
color: #1F2937 !important;
font-family: 'Comic Neue', cursive !important;
font-weight: 700 !important;
}
.gr-dropdown ul {
background: #FFFFFF !important;
border: 3px solid #1F2937 !important;
border-radius: 8px !important;
box-shadow: 4px 4px 0px #1F2937 !important;
}
.gr-dropdown ul li {
color: #1F2937 !important;
font-family: 'Comic Neue', cursive !important;
font-weight: 700 !important;
padding: 8px 12px !important;
}
.gr-dropdown ul li:hover {
background: #FACC15 !important;
color: #1F2937 !important;
}
.gr-dropdown ul li.selected {
background: #3B82F6 !important;
color: #FFFFFF !important;
}
/* ===== π¨ Primary λ²νΌ - μ½λ―Ή λΈλ£¨ ===== */
.gr-button-primary,
button.primary,
.gr-button.primary,
.generate-btn {
background: #3B82F6 !important;
border: 3px solid #1F2937 !important;
border-radius: 8px !important;
color: #FFFFFF !important;
font-family: 'Bangers', cursive !important;
font-weight: 400 !important;
font-size: 1.3rem !important;
letter-spacing: 2px !important;
padding: 14px 28px !important;
box-shadow: 5px 5px 0px #1F2937 !important;
transition: all 0.1s ease !important;
text-shadow: 1px 1px 0px #1F2937 !important;
}
.gr-button-primary:hover,
button.primary:hover,
.gr-button.primary:hover,
.generate-btn:hover {
background: #2563EB !important;
transform: translate(-2px, -2px) !important;
box-shadow: 7px 7px 0px #1F2937 !important;
}
.gr-button-primary:active,
button.primary:active,
.gr-button.primary:active,
.generate-btn:active {
transform: translate(3px, 3px) !important;
box-shadow: 2px 2px 0px #1F2937 !important;
}
/* ===== π¨ Secondary λ²νΌ - μ½λ―Ή λ λ ===== */
.gr-button-secondary,
button.secondary {
background: #EF4444 !important;
border: 3px solid #1F2937 !important;
border-radius: 8px !important;
color: #FFFFFF !important;
font-family: 'Bangers', cursive !important;
font-weight: 400 !important;
font-size: 1.1rem !important;
letter-spacing: 1px !important;
box-shadow: 4px 4px 0px #1F2937 !important;
transition: all 0.1s ease !important;
text-shadow: 1px 1px 0px #1F2937 !important;
}
.gr-button-secondary:hover,
button.secondary:hover {
background: #DC2626 !important;
transform: translate(-2px, -2px) !important;
box-shadow: 6px 6px 0px #1F2937 !important;
}
/* ===== π¨ λ‘κ·Έ μΆλ ₯ μμ ===== */
.info-log textarea {
background: #1F2937 !important;
color: #10B981 !important;
font-family: 'Courier New', monospace !important;
font-size: 0.9rem !important;
font-weight: 400 !important;
border: 3px solid #10B981 !important;
border-radius: 8px !important;
box-shadow: 4px 4px 0px #10B981 !important;
}
/* ===== π¨ μ»¬λ¬ νΌμ»€ μ€νμΌ ===== */
.gr-colorpicker,
input[type="color"] {
border: 3px solid #1F2937 !important;
border-radius: 8px !important;
box-shadow: 3px 3px 0px #1F2937 !important;
width: 60px !important;
height: 40px !important;
cursor: pointer !important;
}
.gr-colorpicker:hover,
input[type="color"]:hover {
transform: translate(-2px, -2px) !important;
box-shadow: 5px 5px 0px #1F2937 !important;
}
/* ===== π¨ μ¬λΌμ΄λ μ€νμΌ ===== */
input[type="range"] {
accent-color: #3B82F6 !important;
height: 8px !important;
}
.gr-slider {
background: #FFFFFF !important;
}
/* ===== π¨ μμ ν
μ€νΈ λ°μ€ ===== */
.example-box textarea {
background: #FEF3C7 !important;
border: 2px dashed #F59E0B !important;
border-radius: 8px !important;
color: #92400E !important;
font-family: 'Comic Neue', cursive !important;
font-size: 0.9rem !important;
}
/* ===== π¨ QR μ½λ μΆλ ₯ μμ ===== */
.qr-output,
.gr-image {
border: 4px solid #1F2937 !important;
border-radius: 8px !important;
box-shadow: 8px 8px 0px #1F2937 !important;
overflow: hidden !important;
background: #FFFFFF !important;
}
/* ===== π¨ μμ½λμΈ - λ§νμ μ€νμΌ ===== */
.gr-accordion {
background: #FACC15 !important;
border: 3px solid #1F2937 !important;
border-radius: 8px !important;
box-shadow: 4px 4px 0px #1F2937 !important;
}
.gr-accordion-header {
color: #1F2937 !important;
font-family: 'Comic Neue', cursive !important;
font-weight: 700 !important;
font-size: 1.1rem !important;
}
/* ===== π¨ λΌλ²¨ μ€νμΌ ===== */
label,
.gr-input-label,
.gr-block-label {
color: #1F2937 !important;
font-family: 'Comic Neue', cursive !important;
font-weight: 700 !important;
font-size: 1rem !important;
}
span.gr-label {
color: #1F2937 !important;
}
/* ===== π¨ μ 보 ν
μ€νΈ ===== */
.gr-info,
.info {
color: #6B7280 !important;
font-family: 'Comic Neue', cursive !important;
font-size: 0.9rem !important;
}
/* ===== π¨ Instructions μΉμ
===== */
.instructions-box {
background: linear-gradient(135deg, #EFF6FF 0%, #DBEAFE 100%) !important;
border: 3px solid #3B82F6 !important;
border-radius: 12px !important;
padding: 1.5rem !important;
box-shadow: 6px 6px 0px #1F2937 !important;
margin-top: 1.5rem !important;
}
.instructions-box h3 {
font-family: 'Bangers', cursive !important;
color: #1F2937 !important;
font-size: 1.3rem !important;
margin-bottom: 0.5rem !important;
}
.instructions-box ul,
.instructions-box ol {
font-family: 'Comic Neue', cursive !important;
color: #1F2937 !important;
font-weight: 700 !important;
}
/* ===== π¨ Tips μΉμ
===== */
.tips-box {
background: linear-gradient(135deg, #FEF3C7 0%, #FDE68A 100%) !important;
border: 3px solid #F59E0B !important;
border-radius: 12px !important;
padding: 1.5rem !important;
box-shadow: 6px 6px 0px #1F2937 !important;
margin-top: 1rem !important;
}
/* ===== π¨ μ€ν¬λ‘€λ° - μ½λ―Ή μ€νμΌ ===== */
::-webkit-scrollbar {
width: 12px;
height: 12px;
}
::-webkit-scrollbar-track {
background: #FEF9C3;
border: 2px solid #1F2937;
}
::-webkit-scrollbar-thumb {
background: #3B82F6;
border: 2px solid #1F2937;
border-radius: 0px;
}
::-webkit-scrollbar-thumb:hover {
background: #EF4444;
}
/* ===== π¨ μ ν νμ΄λΌμ΄νΈ ===== */
::selection {
background: #FACC15;
color: #1F2937;
}
/* ===== π¨ λ§ν¬ μ€νμΌ ===== */
a {
color: #3B82F6 !important;
text-decoration: none !important;
font-weight: 700 !important;
}
a:hover {
color: #EF4444 !important;
}
/* ===== π¨ Row/Column κ°κ²© ===== */
.gr-row {
gap: 1.5rem !important;
}
.gr-column {
gap: 1rem !important;
}
/* ===== π¨ μ»¬λ¬ νΌμ»€ Row ===== */
.color-picker-row {
display: flex !important;
gap: 1rem !important;
align-items: center !important;
}
/* ===== λ°μν μ‘°μ ===== */
@media (max-width: 768px) {
.header-text h1 {
font-size: 2.2rem !important;
text-shadow:
3px 3px 0px #FACC15,
4px 4px 0px #1F2937 !important;
}
.gr-button-primary,
button.primary {
padding: 12px 20px !important;
font-size: 1.1rem !important;
}
.gr-panel,
.block {
box-shadow: 4px 4px 0px #1F2937 !important;
}
}
/* ===== π¨ λ€ν¬λͺ¨λ λΉνμ±ν ===== */
@media (prefers-color-scheme: dark) {
.gradio-container {
background-color: #FEF9C3 !important;
}
}
"""
def create_interface():
with gr.Blocks(fill_height=True, css=css, title="QR Canvas+") as demo:
# HOME Badge
gr.HTML("""
<div style="text-align: center; margin: 20px 0 10px 0;">
<a href="https://www.humangen.ai" target="_blank" style="text-decoration: none;">
<img src="https://img.shields.io/static/v1?label=π HOME&message=HUMANGEN.AI&color=0000ff&labelColor=ffcc00&style=for-the-badge" alt="HOME">
</a>
</div>
""")
# Header Title
gr.Markdown(
"""
# π― QR CANVAS+ GENERATOR π±
""",
elem_classes="header-text"
)
gr.Markdown(
"""
<p class="subtitle">π¨ Create customized QR codes with professional styling & decorations! β¨</p>
""",
)
with gr.Row(equal_height=False):
# Left column - Input Settings
with gr.Column(scale=2, min_width=450):
qr_type = gr.Dropdown(
choices=["URL", "Email", "Phone", "SMS", "WhatsApp", "Location", "Wi-Fi", "Text", "vCard"],
value="URL",
label="π QR Code Type"
)
content = gr.Textbox(
label="βοΈ Content",
placeholder="Enter your content here...",
lines=3
)
example_format = gr.Textbox(
value=format_example_text("URL"),
label="π Format Examples",
interactive=False,
lines=4,
elem_classes="example-box"
)
with gr.Row(elem_classes="color-picker-row"):
fill_color = gr.ColorPicker(
label="π¨ QR Code Color",
value="#000000"
)
back_color = gr.ColorPicker(
label="πΌοΈ Background Color",
value="#FFFFFF"
)
with gr.Row():
box_size = gr.Slider(
minimum=1,
maximum=30,
value=15,
step=1,
label="π QR Code Size"
)
border_size = gr.Slider(
minimum=0,
maximum=5,
value=2,
step=1,
label="π² Border Size"
)
error_correction = gr.Dropdown(
choices=[
"Low (7%)",
"Medium (15%)",
"Quartile (25%)",
"High (30%)"
],
value="Medium (15%)",
label="π§ Error Correction Level"
)
border_decoration = gr.Dropdown(
choices=[
"No Decoration",
"Flowers",
"Hearts",
"Waves",
"Leaves",
"Stars",
"Chains",
"Bubbles",
"Vines",
"Diamonds",
"Lace"
],
value="No Decoration",
label="πΈ Border Decoration Style"
)
generate_btn = gr.Button(
"π― GENERATE QR CODE! π±",
variant="primary",
size="lg",
elem_classes="generate-btn"
)
with gr.Accordion("π Generation Log", open=True):
info_log = gr.Textbox(
label="",
placeholder="Enter content and click generate to see info...",
lines=14,
max_lines=20,
interactive=False,
elem_classes="info-log"
)
# Right column - Output
with gr.Column(scale=1, min_width=350):
output_image = gr.Image(
label="πΌοΈ Generated QR Code",
type="filepath",
height=400,
elem_classes="qr-output"
)
output_data = gr.Textbox(
label="π Formatted Data",
interactive=False,
lines=2
)
gr.Markdown(
"""
<p style="text-align: center; margin-top: 15px; font-weight: 700; color: #1F2937;">
π‘ Right-click on the QR code to save!
</p>
"""
)
# Instructions Section
gr.Markdown(
"""
<div class="instructions-box">
<h3>π INSTRUCTIONS</h3>
<ol>
<li>Select the QR code type from the dropdown menu</li>
<li>Enter your content following the format examples shown</li>
<li>Customize the appearance using the color pickers and sliders</li>
<li>Choose a border decoration style (optional)</li>
<li>Click 'GENERATE QR CODE' to create your custom QR code</li>
</ol>
</div>
<div class="tips-box">
<h3>π‘ TIPS</h3>
<ul>
<li>Use higher error correction levels for better scan reliability</li>
<li>Ensure sufficient contrast between QR code and background colors</li>
<li>Keep the content concise for better readability</li>
<li>Follow the format examples for best results</li>
</ul>
</div>
"""
)
# Event handlers
def update_example(qr_type):
return format_example_text(qr_type)
qr_type.change(
fn=update_example,
inputs=[qr_type],
outputs=example_format
)
generate_btn.click(
fn=create_qr,
inputs=[
content,
qr_type,
fill_color,
back_color,
box_size,
border_size,
error_correction,
border_decoration
],
outputs=[output_image, output_data, info_log]
)
return demo
if __name__ == "__main__":
try:
os.makedirs("qrfile", exist_ok=True)
demo = create_interface()
demo.launch(
server_name="0.0.0.0",
server_port=7860,
share=True,
debug=True
)
except Exception as e:
print(f"Error starting the application: {e}") |