| | import urllib.parse |
| | import gradio as gr |
| |
|
| | |
| | |
| | |
| |
|
| | 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 |
| |
|
| |
|
| | |
| | |
| | |
| |
|
| | 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; |
| | } |
| | } |
| | """ |
| |
|
| | |
| | |
| | |
| | with gr.Blocks(fill_height=True, css=css, title="BadgeCraft") as demo: |
| | |
| | |
| | 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> |
| | """) |
| | |
| | |
| | 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> |
| | """, |
| | ) |
| |
|
| | |
| | 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> |
| | """ |
| | ) |
| |
|
| | |
| | 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"], |
| | ] |
| |
|
| | |
| | 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() |