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'
'
else:
html_code = f'
'
badge_preview = f"""
{html_code}
"""
# 정보 로그 생성
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("""
""")
# Header Title
gr.Markdown(
"""
# 🎨 BADGECRAFT GENERATOR 🏷️
""",
elem_classes="header-text"
)
gr.Markdown(
"""
✨ Create beautiful badges with live preview and HTML snippet! 💻
✨ MIT License
👥 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(equal_height=False):
with gr.Column(scale=1, min_width=400):
with gr.Group(elem_classes="badge-section"):
gr.HTML("✏️ BADGE SETTINGS
")
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("👁️ LIVE 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)
gr.Markdown(
"""
💡 Copy the HTML code and paste it into your website or README!
"""
)
# 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(
"""
🌟 CLICK AN EXAMPLE TO USE! 🌟
"""
)
html_items = ''
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'''
{ex[0]}
'''
html_items += '
'
apply_example_js = """
"""
gr.HTML(html_items + apply_example_js)
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
- Label: Text displayed on the left side of the badge (e.g., "Discord", "Version", "Status")
- Message: Text displayed on the right side of the badge
- Logo: Name of a logo provided by Simple Icons (View List)
- Style: Determines the shape of the badge (flat, plastic, for-the-badge, etc.)
🎨 Color Settings
- Background Color: Background color for the right side of the badge
- Label Background Color: Background color for the left side of the badge
- Logo Color: Color of the logo (e.g. white or black)
🔗 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 .
💡 Tips
- Click on any example in the grid to automatically fill in all settings
- The preview updates in real-time as you make changes
- You can use over 2000+ logos from Simple Icons - just enter the name
- Choose from predefined colors in the dropdown menus for consistent results
''')
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()