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'badge' else: html_code = f'badge' badge_preview = f"""
{html_code}
""" return html_code, badge_preview # --------------------------- # Gradio UI # --------------------------- with gr.Blocks(theme=gr.themes.Soft()) as demo: # Custom CSS gr.HTML(""" """) # Header section gr.HTML("""

🎨 BadgeCraft

Create beautiful badges with live preview and HTML snippet

✨ MIT License πŸ‘₯ Created by OpenFreeAI Team
""") # 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(): with gr.Column(): with gr.Group(elem_classes="badge-section"): gr.HTML("

✏️ Badge Settings

") label = gr.Textbox(label="Label", value="Discord", elem_id="label-input", lines=1) message = gr.Textbox(label="Message", value="Join our community", elem_id="message-input", lines=1) logo = gr.Textbox(label="Logo", value="discord", elem_id="logo-input", lines=1) style = gr.Dropdown( label="Style", choices=["flat", "flat-square", "plastic", "for-the-badge", "social"], value="for-the-badge", elem_id="style-input" ) # Replace color pickers with dropdown selections color_choices = [f"
{name}
" for name, hex_code in color_options.items()] color = gr.Dropdown( label="Background Color", choices=list(color_options.keys()), value="Blue", elem_id="color-input" ) label_color = gr.Dropdown( label="Label Background Color", choices=list(color_options.keys()), value="Purple", elem_id="label-color-input" ) logo_color = gr.Dropdown( label="Logo Color", choices=["white", "black"] + list(color_options.keys()), value="white", elem_id="logo-color-input" ) link = gr.Textbox(label="Link (URL)", value="https://discord.gg/openfreeai", elem_id="link-input", lines=1) with gr.Column(): with gr.Group(elem_classes="badge-section"): gr.HTML("

πŸ‘οΈ Preview

") out_preview = gr.HTML(label="") with gr.Group(elem_classes="badge-section"): gr.HTML("

πŸ’» HTML Code

") out_code = gr.Code(label="", language="html", lines=3) # 예제 리슀트 (label, message, bg_color, label_color, logo, logo_color, style, link) 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"], ] # 예제 미리보기 html_items = '
' for idx, ex in enumerate(examples): # ex = [label, message, bg_color, label_color, logo, logo_color, style, link] 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'''
{ex[0]} badge
{ex[0]}
''' html_items += '
' # 예제λ₯Ό ν΄λ¦­ν–ˆμ„ λ•Œ μ μš©ν•˜λŠ” main ν•¨μˆ˜ apply_example_js = """ """ gr.HTML(html_items + apply_example_js) # ν•¨μˆ˜λ₯Ό μˆ˜μ •ν•˜μ—¬ 색상 값을 λ³€ν™˜ def process_badge(label, message, color_name, label_color_name, logo, logo_color_name, style, link): # 색상 이름을 hex μ½”λ“œλ‘œ λ³€ν™˜ color_hex = color_options.get(color_name, "#000000") label_color_hex = color_options.get(label_color_name, "#000000") # logo_colorκ°€ whiteλ‚˜ black인 경우 κ·ΈλŒ€λ‘œ μ‚¬μš©, μ•„λ‹ˆλ©΄ hex μ½”λ“œλ‘œ λ³€ν™˜ if logo_color_name in ["white", "black"]: logo_color_hex = logo_color_name else: logo_color_hex = 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] ) 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] ) with gr.TabItem("Help"): gr.HTML('''

πŸ“‹ How to Use BadgeCraft

✨ What are Badges?

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.

πŸ› οΈ Basic Settings

🎨 ColorSettings

πŸ”— Using the HTML

Copy the generated HTML code and paste it into your website, blog, GitHub README, etc.

HTML works in GitHub READMEs, but if you prefer markdown, use ![alt text](badge URL).

πŸ’‘ Tips

''') # Footer gr.HTML(''' ''') if __name__ == "__main__": demo.launch()