File size: 7,364 Bytes
d175de0 754b04a d175de0 c7d31e2 adfeb27 542620e 448bf0e adfeb27 448bf0e adfeb27 448bf0e adfeb27 448bf0e 542620e 448bf0e 5a5c985 448bf0e adfeb27 542620e adfeb27 d175de0 c7d31e2 754b04a d175de0 c7d31e2 d175de0 adfeb27 d175de0 c7d31e2 d175de0 adfeb27 542620e |
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 |
import urllib.parse
import gradio as gr
# ---------------------------
# ๋ฐฐ์ง URL ์์ฑ ํจ์ ์ ์
# ---------------------------
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:20px; background: #fefefe; border-radius: 12px; display: flex; justify-content: center;'>
{html_code}
</div>
"""
return html_code, badge_preview
# ---------------------------
# Gradio UI ๊ตฌ์ฑ
# ---------------------------
with gr.Blocks(theme=gr.themes.Default()) as demo:
# ๊ธฐ์กด static ์์ ์์ด์ฝ๋ค
gr.HTML("""
<h1 style="text-align: center; font-size: 2.2em; margin-bottom: 0.2em;">๐จ BadgeCraft - Beautiful Badge Generator</h1>
<p style="text-align: center; font-size: 1.1em; color: #555;">Design stylish shields.io badges with live preview and HTML snippet generation.</p>
<h3 style="text-align: center; margin-top: 30px;">โจ Examples</h3>
<div align="center" style="display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; margin: 10px 0 30px; justify-items: center;">
<a href="https://discord.gg/openfreeai">
<img alt="Discord" src="https://img.shields.io/badge/Discord-5865F2?style=for-the-badge&logo=discord&logoColor=white" />
</a>
<a href="https://x.com/openfree_ai">
<img alt="X" src="https://img.shields.io/badge/X.com-000000?style=for-the-badge&logo=X&logoColor=white" />
</a>
<a href="https://huggingface.co/collections/VIDraft/best-open-ai-services-68057e6e312880ea92abaf4c">
<img alt="Collections" src="https://img.shields.io/badge/Collections-F8F8F8?style=for-the-badge&logo=huggingface&logoColor=black" />
</a>
<a href="https://huggingface.co/VIDraft">
<img alt="VIDraft" src="https://img.shields.io/badge/VIDraft-FCD022?style=for-the-badge&logo=huggingface&logoColor=black" />
</a>
<a href="https://github.com/openfreeai">
<img src="https://img.shields.io/badge/GitHub-181717?style=for-the-badge&logo=github&logoColor=white" alt="GitHub">
</a>
<a href="https://twitter.com/openfree_ai">
<img src="https://img.shields.io/badge/Twitter-1DA1F2?style=for-the-badge&logo=twitter&logoColor=white" alt="Twitter">
</a>
<a href="https://www.linkedin.com/company/openfreeai">
<img src="https://img.shields.io/badge/LinkedIn-0077B5?style=for-the-badge&logo=linkedin&logoColor=white" alt="LinkedIn">
</a>
<a href="https://www.youtube.com/@AITechTree">
<img src="https://img.shields.io/badge/YouTube-FF0000?style=for-the-badge&logo=youtube&logoColor=white" alt="YouTube">
</a>
<a href="https://huggingface.co/openfreeai">
<img src="https://img.shields.io/badge/HuggingFace-FCC72E?style=for-the-badge&logo=huggingface&logoColor=black" alt="HuggingFace">
</a>
<a href="https://www.instagram.com/openfree_ai">
<img src="https://img.shields.io/badge/Instagram-E4405F?style=for-the-badge&logo=instagram&logoColor=white" alt="Instagram">
</a>
<a href="https://www.threads.net/@openfree_ai">
<img src="https://img.shields.io/badge/Threads-000000?style=for-the-badge&logo=threads&logoColor=white" alt="Threads">
</a>
<a href="https://www.facebook.com/profile.php?id=61575353674679">
<img src="https://img.shields.io/badge/Facebook-1877F2?style=for-the-badge&logo=facebook&logoColor=white" alt="Facebook">
</a>
</div>
""")
# ์ถ๋ ฅ ์ปดํฌ๋ํธ
with gr.Row():
out_code = gr.Code(label="HTML Snippet", language="html")
out_preview = gr.HTML(label="Badge Preview")
# ์
๋ ฅ ์ปดํฌ๋ํธ
with gr.Row():
label = gr.Textbox(label="Label", placeholder="์: build")
message = gr.Textbox(label="Message", placeholder="์: passing")
logo = gr.Textbox(label="Logo", placeholder="์: github")
with gr.Row():
color = gr.ColorPicker(label="Color", value="#a0c4ff")
label_color = gr.ColorPicker(label="Label Color", value="#bdb2ff")
logo_color = gr.ColorPicker(label="Logo Color", value="#ffc6ff")
style = gr.Dropdown(label="Style", choices=["flat", "flat-square", "plastic", "for-the-badge", "social"], value="for-the-badge")
link = gr.Textbox(label="Link (๋ฐฐ์ง ํด๋ฆญ ์ ์ด๋ํ URL)", placeholder="https://yourlink.com")
# Examples ๋ฐ์ดํฐ (8๊ฐ ํ๋ ์์๋๋ก)
examples = [
["Discord", "5865F2", "", "", "discord", "white", "for-the-badge", "https://discord.gg/openfreeai"],
["X.com", "000000", "", "", "X", "white", "for-the-badge", "https://x.com/openfree_ai"],
["Collections","F8F8F8", "", "", "huggingface","black", "for-the-badge", "https://huggingface.co/collections/VIDraft/best-open-ai-services-68057e6e312880ea92abaf4c"],
["VIDraft", "FCD022", "", "", "huggingface","black", "for-the-badge", "https://huggingface.co/VIDraft"],
["GitHub", "181717", "", "", "github", "white", "for-the-badge", "https://github.com/openfreeai"],
["Twitter", "1DA1F2", "", "", "twitter", "white", "for-the-badge", "https://twitter.com/openfree_ai"],
["YouTube", "FF0000", "", "", "youtube", "white", "for-the-badge", "https://www.youtube.com/@AITechTree"],
["Instagram", "E4405F", "", "", "instagram", "white", "for-the-badge", "https://www.instagram.com/openfree_ai"],
["Threads", "000000", "", "", "threads", "white", "for-the-badge", "https://www.threads.net/@openfree_ai"],
["Facebook", "1877F2", "", "", "facebook", "white", "for-the-badge", "https://www.facebook.com/profile.php?id=61575353674679"],
]
gr.HTML("<h3 style='text-align: center; margin-top: 30px;'>โจ Click an example to autofill</h3>")
gr.Examples(
examples=examples,
inputs=[label, message, color, label_color, logo, logo_color, style, link],
outputs=[out_code, out_preview],
fn=generate_static_badge,
cache_examples=False,
run_on_click=True
)
# ์ค์๊ฐ change ์ด๋ฒคํธ ๋ฐ์ธ๋ฉ
inputs = [label, message, color, label_color, logo, logo_color, style, link]
for inp in inputs:
inp.change(fn=generate_static_badge, inputs=inputs, outputs=[out_code, out_preview])
# ์คํ
if __name__ == "__main__":
demo.launch()
|