File size: 27,830 Bytes
d64466a dd9c631 afe2127 dd9c631 18d8ce4 dd9c631 d64466a dd9c631 7993a52 dd9c631 7993a52 5fbecf9 7993a52 5fbecf9 7993a52 d5ad155 dd9c631 7993a52 afe2127 7993a52 afe2127 7993a52 afe2127 7993a52 07f7a33 7993a52 98acb26 dd9c631 2c52707 7993a52 2c52707 7993a52 dd9c631 7993a52 dd9c631 7993a52 dd9c631 afe2127 dd9c631 7993a52 dd9c631 7993a52 dd9c631 7993a52 dd9c631 7993a52 dd9c631 7993a52 dd9c631 7993a52 dd9c631 7993a52 2c52707 7993a52 dd9c631 7993a52 2c52707 7993a52 dd9c631 7993a52 18d8ce4 7993a52 18d8ce4 dd9c631 18d8ce4 afe2127 7993a52 18d8ce4 dd9c631 afe2127 dd9c631 18d8ce4 dd9c631 7993a52 18d8ce4 dd9c631 18d8ce4 dd9c631 18d8ce4 dd9c631 afe2127 18d8ce4 dd9c631 18d8ce4 2c52707 7993a52 2c52707 7993a52 dd9c631 7993a52 dd9c631 7993a52 dd9c631 7993a52 dd9c631 7993a52 dd9c631 2c52707 7993a52 d64466a 5fbecf9 | 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 | import urllib.parse
import gradio as gr
# ---------------------------
# Badge URL generation
# ---------------------------
def generate_static_badge(label, message, color, label_color, logo, logo_color, style, link):
base = "https://img.shields.io/static/v1"
params = []
if label:
params.append(f"label={urllib.parse.quote(label, safe='')}")
if message:
params.append(f"message={urllib.parse.quote(message, safe='')}")
if color:
params.append(f"color={urllib.parse.quote(color, safe='')}")
if label_color:
params.append(f"labelColor={urllib.parse.quote(label_color, safe='')}")
if logo:
params.append(f"logo={urllib.parse.quote(logo, safe='')}")
if logo_color:
params.append(f"logoColor={urllib.parse.quote(logo_color, safe='')}")
if style:
params.append(f"style={urllib.parse.quote(style, safe='')}")
badge_url = base + ("?" + "&".join(params) if params else "")
if link:
html_code = f'<a href="{link}" target="_blank"><img src="{badge_url}" alt="badge"></a>'
else:
html_code = f'<img src="{badge_url}" alt="badge">'
badge_preview = f"""
<div style='padding:30px; background: #FFFFFF;
border: 4px solid #1F2937; border-radius: 12px;
display: flex; justify-content: center;
box-shadow: 6px 6px 0px #1F2937;'>
{html_code}
</div>
"""
# μ 보 λ‘κ·Έ μμ±
info_log = f"""β
BADGE GENERATED!
{'=' * 50}
π·οΈ Badge Info:
β’ Label: {label}
β’ Message: {message}
β’ Logo: {logo}
{'=' * 50}
π¨ Style Settings:
β’ Background: {color}
β’ Label Color: {label_color}
β’ Logo Color: {logo_color}
β’ Style: {style}
{'=' * 50}
π Link: {link if link else 'None'}
{'=' * 50}
πΎ HTML code ready to copy!"""
return html_code, badge_preview, info_log
# ============================================
# π¨ 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,
.gr-group {
background: #FFFFFF !important;
border: 3px solid #1F2937 !important;
border-radius: 8px !important;
box-shadow: 6px 6px 0px #1F2937 !important;
}
/* block hover ν¨κ³Ό μ κ±° - λλ‘λ€μ΄ ν΄λ¦ λ°©ν΄ λ°©μ§ */
/* ===== π¨ μ
λ ₯ νλ (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;
}
/* ===== π¨ λλ‘λ€μ΄ μ€νμΌ - κΈ°λ³Έ μ μ§, ν°νΈλ§ λ³κ²½ ===== */
/* λλ‘λ€μ΄μ Gradio κΈ°λ³Έ μ€νμΌ μ¬μ© (ν΄λ¦ λ¬Έμ λ°©μ§) */
/* ===== π¨ 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-code,
pre,
code {
background: #1F2937 !important;
color: #10B981 !important;
font-family: 'Courier New', monospace !important;
border: 3px solid #10B981 !important;
border-radius: 8px !important;
box-shadow: 4px 4px 0px #10B981 !important;
padding: 12px !important;
}
/* ===== π¨ ν μ€νμΌ ===== */
.gr-tabs {
background: transparent !important;
}
.gr-tab-item {
background: #FFFFFF !important;
border: 3px solid #1F2937 !important;
border-radius: 8px 8px 0 0 !important;
color: #1F2937 !important;
font-family: 'Bangers', cursive !important;
font-size: 1.1rem !important;
letter-spacing: 1px !important;
padding: 10px 20px !important;
margin-right: 4px !important;
box-shadow: 3px -3px 0px #1F2937 !important;
transition: all 0.2s ease !important;
}
.gr-tab-item:hover {
background: #FEF3C7 !important;
transform: translateY(-2px) !important;
}
.gr-tab-item.selected {
background: #3B82F6 !important;
color: #FFFFFF !important;
box-shadow: 4px -4px 0px #1F2937 !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;
}
/* ===== π¨ Example Grid μ€νμΌ ===== */
.example-grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-template-rows: repeat(2, auto);
gap: 16px;
margin-top: 20px;
}
.example-item {
background: #FFFFFF !important;
border: 3px solid #1F2937 !important;
border-radius: 12px !important;
padding: 16px !important;
text-align: center !important;
cursor: pointer !important;
transition: all 0.2s ease !important;
box-shadow: 4px 4px 0px #1F2937 !important;
}
.example-item:hover {
transform: translate(-3px, -3px) !important;
box-shadow: 7px 7px 0px #1F2937 !important;
background: #FEF3C7 !important;
}
.example-item:active {
transform: translate(2px, 2px) !important;
box-shadow: 2px 2px 0px #1F2937 !important;
}
@media (max-width: 768px) {
.example-grid {
grid-template-columns: repeat(2, 1fr);
}
}
@media (max-width: 600px) {
.example-grid {
grid-template-columns: 1fr;
}
}
/* ===== π¨ Badge Section μ€νμΌ ===== */
.badge-section {
background: #FFFFFF !important;
border: 3px solid #1F2937 !important;
border-radius: 12px !important;
padding: 20px !important;
box-shadow: 6px 6px 0px #1F2937 !important;
margin-bottom: 20px !important;
}
.badge-section h3 {
font-family: 'Bangers', cursive !important;
color: #1F2937 !important;
font-size: 1.3rem !important;
letter-spacing: 1px !important;
margin-bottom: 16px !important;
}
/* ===== π¨ Help Section μ€νμΌ ===== */
.help-section {
background: #FFFFFF !important;
border: 3px solid #1F2937 !important;
border-radius: 12px !important;
padding: 24px !important;
box-shadow: 6px 6px 0px #1F2937 !important;
}
.help-section h3 {
font-family: 'Bangers', cursive !important;
color: #3B82F6 !important;
font-size: 1.5rem !important;
letter-spacing: 1px !important;
margin-bottom: 16px !important;
}
.help-section h4 {
font-family: 'Comic Neue', cursive !important;
color: #1F2937 !important;
font-weight: 700 !important;
font-size: 1.1rem !important;
margin: 16px 0 8px 0 !important;
}
.help-section p,
.help-section li {
font-family: 'Comic Neue', cursive !important;
color: #1F2937 !important;
font-size: 1rem !important;
line-height: 1.6 !important;
}
.help-section ul {
padding-left: 20px !important;
}
.help-section a {
color: #3B82F6 !important;
font-weight: 700 !important;
}
.help-section a:hover {
color: #EF4444 !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;
}
/* ===== π¨ License/Credit λ±μ§ ===== */
.license-badge {
display: inline-block;
background: #10B981 !important;
color: #FFFFFF !important;
font-family: 'Comic Neue', cursive !important;
font-weight: 700 !important;
padding: 6px 14px !important;
border: 2px solid #1F2937 !important;
border-radius: 20px !important;
box-shadow: 2px 2px 0px #1F2937 !important;
margin: 4px !important;
}
.credit-badge {
display: inline-block;
background: #3B82F6 !important;
color: #FFFFFF !important;
font-family: 'Comic Neue', cursive !important;
font-weight: 700 !important;
padding: 6px 14px !important;
border: 2px solid #1F2937 !important;
border-radius: 20px !important;
box-shadow: 2px 2px 0px #1F2937 !important;
margin: 4px !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;
}
}
"""
# ---------------------------
# Gradio UI
# ---------------------------
with gr.Blocks(fill_height=True, css=css, title="BadgeCraft") 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(
"""
# π¨ BADGECRAFT GENERATOR π·οΈ
""",
elem_classes="header-text"
)
gr.Markdown(
"""
<p class="subtitle">β¨ Create beautiful badges with live preview and HTML snippet! π»</p>
<div style="text-align: center; margin: 10px 0;">
<span class="license-badge">β¨ MIT License</span>
<span class="credit-badge">π₯ OpenFreeAI Team</span>
</div>
""",
)
# Define color options
color_options = {
"Red": "#ff0000",
"Blue": "#0000ff",
"Green": "#00ff00",
"Yellow": "#ffff00",
"Purple": "#800080",
"Orange": "#ffa500",
"Pink": "#ffc0cb",
"Teal": "#008080",
"Navy": "#000080",
"Lime": "#00ff00",
"Cyan": "#00ffff",
"Magenta": "#ff00ff",
"Gold": "#ffd700",
"Silver": "#c0c0c0"
}
with gr.Tabs():
with gr.TabItem("π¨ Badge Generator"):
with gr.Row(equal_height=False):
with gr.Column(scale=1, min_width=400):
with gr.Group(elem_classes="badge-section"):
gr.HTML("<h3>βοΈ BADGE SETTINGS</h3>")
label = gr.Textbox(
label="π·οΈ Label",
value="Discord",
lines=1
)
message = gr.Textbox(
label="π¬ Message",
value="Join our community",
lines=1
)
logo = gr.Textbox(
label="πΌοΈ Logo",
value="discord",
lines=1
)
style = gr.Dropdown(
label="π Style",
choices=["flat", "flat-square", "plastic", "for-the-badge", "social"],
value="for-the-badge"
)
color = gr.Dropdown(
label="π¨ Background Color",
choices=list(color_options.keys()),
value="Blue"
)
label_color = gr.Dropdown(
label="π·οΈ Label Background Color",
choices=list(color_options.keys()),
value="Purple"
)
logo_color = gr.Dropdown(
label="β¨ Logo Color",
choices=["white", "black"] + list(color_options.keys()),
value="white"
)
link = gr.Textbox(
label="π Link (URL)",
value="https://discord.gg/openfreeai",
lines=1
)
with gr.Accordion("π Generation Log", open=True):
info_log = gr.Textbox(
label="",
placeholder="Badge info will appear here...",
lines=14,
max_lines=20,
interactive=False,
elem_classes="info-log"
)
with gr.Column(scale=1, min_width=400):
with gr.Group(elem_classes="badge-section"):
gr.HTML("<h3>ποΈ LIVE PREVIEW</h3>")
out_preview = gr.HTML(label="")
with gr.Group(elem_classes="badge-section"):
gr.HTML("<h3>π» HTML CODE</h3>")
out_code = gr.Code(label="", language="html", lines=3)
gr.Markdown(
"""
<p style="text-align: center; margin-top: 15px; font-weight: 700; color: #1F2937;">
π‘ Copy the HTML code and paste it into your website or README!
</p>
"""
)
# Example list
examples = [
["Discord", "Openfree AI", "Blue", "Purple", "discord", "white", "for-the-badge", "https://discord.gg/openfreeai"],
["X.com", "Follow us", "Blue", "Cyan", "x", "white", "for-the-badge", "https://x.com/openfree_ai"],
["Collections","Explore", "Orange", "Yellow", "huggingface","black","for-the-badge", "https://huggingface.co/collections/VIDraft/best-open-ai-services-68057e6e312880ea92abaf4c"],
["GitHub", "Star us", "Navy", "Lime", "github", "white", "for-the-badge", "https://github.com/openfreeai"],
["YouTube", "Watch now", "Red", "Orange", "youtube", "white", "for-the-badge", "https://www.youtube.com/@AITechTree"],
["Facebook", "Like us", "Blue", "Cyan", "facebook", "white", "for-the-badge", "https://www.facebook.com/profile.php?id=61575353674679"],
["Instagram", "εζ
θ¬δΈ", "Magenta", "Pink", "instagram", "white", "for-the-badge", "https://www.instagram.com/openfree_ai/"],
["Threads", "ν¨κ» μ¦κ²¨μ.", "Navy", "Magenta", "threads", "white", "for-the-badge", "https://www.threads.net/@openfree_ai"],
]
# Example grid preview
gr.Markdown(
"""
<p style="text-align: center; margin: 25px 0 15px 0; font-family: 'Bangers', cursive; font-size: 1.5rem; color: #1F2937;">
π CLICK AN EXAMPLE TO USE! π
</p>
"""
)
html_items = '<div class="example-grid">'
for idx, ex in enumerate(examples):
color_hex = color_options.get(ex[2], ex[2])
label_color_hex = color_options.get(ex[3], ex[3])
logo_color_val = color_options.get(ex[5], ex[5]) if ex[5] in color_options else ex[5]
badge_url = (
"https://img.shields.io/static/v1?" + "&".join([
f"label={urllib.parse.quote(ex[0], safe='')}",
f"message={urllib.parse.quote(ex[1], safe='')}",
f"color={urllib.parse.quote(color_hex, safe='')}",
f"labelColor={urllib.parse.quote(label_color_hex, safe='')}",
f"logo={urllib.parse.quote(ex[4], safe='')}",
f"logoColor={urllib.parse.quote(logo_color_val, safe='')}",
f"style={urllib.parse.quote(ex[6], safe='')}",
])
)
html_items += f'''
<div class="example-item" onclick="applyExample({idx})">
<img src="{badge_url}" alt="{ex[0]} badge" style="margin-bottom:8px;">
<div style="font-size:0.9rem; color:#1F2937; font-family: 'Comic Neue', cursive; font-weight: 700;">{ex[0]}</div>
</div>
'''
html_items += '</div>'
apply_example_js = """
<script>
function updateSelectValue(selectEl, newValue) {
if (!selectEl) return;
selectEl.value = newValue;
selectEl.dispatchEvent(new Event("change", { bubbles: true }));
}
function updateTextValue(el, newValue) {
if (!el) return;
el.value = newValue;
el.dispatchEvent(new Event("input", { bubbles: true }));
el.dispatchEvent(new Event("change", { bubbles: true }));
}
const examples = """ + str(examples).replace("'", '"') + """;
function applyExample(i) {
const ex = examples[i];
const selectors = {
label: "#label-input",
message: "#message-input",
color: "#color-input select",
labelColor: "#label-color-input select",
logo: "#logo-input",
logoColor: "#logo-color-input select",
style: "#style-input select",
link: "#link-input"
};
const labelBox = document.querySelector(`${selectors.label} textarea, ${selectors.label} input`);
if (labelBox) { updateTextValue(labelBox, ex[0]); }
const msgBox = document.querySelector(`${selectors.message} textarea, ${selectors.message} input`);
if (msgBox) { updateTextValue(msgBox, ex[1]); }
const bgColorSelect = document.querySelector(selectors.color);
if (bgColorSelect) { updateSelectValue(bgColorSelect, ex[2]); }
const labelColorSelect = document.querySelector(selectors.labelColor);
if (labelColorSelect) { updateSelectValue(labelColorSelect, ex[3]); }
const logoBox = document.querySelector(`${selectors.logo} textarea, ${selectors.logo} input`);
if (logoBox) { updateTextValue(logoBox, ex[4]); }
const logoColorSelect = document.querySelector(selectors.logoColor);
if (logoColorSelect) { updateSelectValue(logoColorSelect, ex[5]); }
const styleSelect = document.querySelector(selectors.style);
if (styleSelect) { updateSelectValue(styleSelect, ex[6]); }
const linkBox = document.querySelector(`${selectors.link} textarea, ${selectors.link} input`);
if (linkBox) { updateTextValue(linkBox, ex[7]); }
}
</script>
"""
gr.HTML(html_items + apply_example_js)
with gr.TabItem("β Help"):
gr.HTML('''
<div class="help-section">
<h3>π HOW TO USE BADGECRAFT</h3>
<h4>β¨ What are Badges?</h4>
<p>Badges are small visual indicators that can be used in README files, websites, and documentation. Shields.io badges are widely used to display project status, social media links, version information, and more.</p>
<h4>π οΈ Basic Settings</h4>
<ul>
<li><strong>Label</strong>: Text displayed on the left side of the badge (e.g., "Discord", "Version", "Status")</li>
<li><strong>Message</strong>: Text displayed on the right side of the badge</li>
<li><strong>Logo</strong>: Name of a logo provided by Simple Icons (<a href="https://simpleicons.org/" target="_blank">View List</a>)</li>
<li><strong>Style</strong>: Determines the shape of the badge (flat, plastic, for-the-badge, etc.)</li>
</ul>
<h4>π¨ Color Settings</h4>
<ul>
<li><strong>Background Color</strong>: Background color for the right side of the badge</li>
<li><strong>Label Background Color</strong>: Background color for the left side of the badge</li>
<li><strong>Logo Color</strong>: Color of the logo (e.g. white or black)</li>
</ul>
<h4>π Using the HTML</h4>
<p>Copy the generated HTML code and paste it into your website, blog, GitHub README, etc.</p>
<p>HTML works in GitHub READMEs, but if you prefer markdown, use <code></code>.</p>
<h4>π‘ Tips</h4>
<ul>
<li>Click on any example in the grid to automatically fill in all settings</li>
<li>The preview updates in real-time as you make changes</li>
<li>You can use over 2000+ logos from Simple Icons - just enter the name</li>
<li>Choose from predefined colors in the dropdown menus for consistent results</li>
</ul>
</div>
''')
def process_badge(label, message, color_name, label_color_name, logo, logo_color_name, style, link):
color_hex = color_options.get(color_name, "#000000")
label_color_hex = color_options.get(label_color_name, "#000000")
logo_color_hex = logo_color_name if logo_color_name in ["white", "black"] else color_options.get(logo_color_name, "#ffffff")
return generate_static_badge(label, message, color_hex, label_color_hex, logo, logo_color_hex, style, link)
demo.load(
fn=process_badge,
inputs=[label, message, color, label_color, logo, logo_color, style, link],
outputs=[out_code, out_preview, info_log],
)
for inp in [label, message, color, label_color, logo, logo_color, style, link]:
inp.change(
fn=process_badge,
inputs=[label, message, color, label_color, logo, logo_color, style, link],
outputs=[out_code, out_preview, info_log],
)
if __name__ == "__main__":
demo.launch() |