Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,7 @@ import urllib.parse
|
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
# ---------------------------
|
| 5 |
-
#
|
| 6 |
# ---------------------------
|
| 7 |
def generate_static_badge(label, message, color, label_color, logo, logo_color, style, link):
|
| 8 |
base = "https://img.shields.io/static/v1"
|
|
@@ -36,56 +36,74 @@ def generate_static_badge(label, message, color, label_color, logo, logo_color,
|
|
| 36 |
return html_code, badge_preview
|
| 37 |
|
| 38 |
# ---------------------------
|
| 39 |
-
# Gradio UI
|
| 40 |
# ---------------------------
|
| 41 |
with gr.Blocks(theme=gr.themes.Default()) as demo:
|
|
|
|
| 42 |
gr.HTML("""
|
| 43 |
-
<
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
""")
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
-
#
|
| 52 |
with gr.Row():
|
| 53 |
-
label = gr.Textbox(label="Label", placeholder="
|
| 54 |
-
message = gr.Textbox(label="Message", placeholder="
|
| 55 |
-
logo = gr.Textbox(label="Logo", placeholder="
|
| 56 |
with gr.Row():
|
| 57 |
-
color = gr.ColorPicker(label="Color", value="#
|
| 58 |
-
label_color = gr.ColorPicker(label="Label Color", value="#
|
| 59 |
-
logo_color = gr.ColorPicker(label="Logo Color", value="
|
| 60 |
-
style = gr.Dropdown(label="Style", choices=["flat",
|
| 61 |
-
link = gr.Textbox(label="Link (
|
| 62 |
|
| 63 |
-
#
|
| 64 |
examples = [
|
| 65 |
-
["Discord",
|
| 66 |
-
["X.com",
|
| 67 |
-
["Collections",
|
| 68 |
-
["GitHub",
|
| 69 |
-
["YouTube",
|
| 70 |
-
["Facebook",
|
| 71 |
-
["Instagram",
|
| 72 |
-
["Threads", "
|
| 73 |
]
|
| 74 |
-
gr.HTML("<h3 style='text-align:center; margin-top:20px;'>โจ Examples (
|
| 75 |
gr.Examples(
|
| 76 |
examples=examples,
|
| 77 |
-
inputs=[label,
|
| 78 |
-
outputs=[out_code,
|
| 79 |
fn=generate_static_badge,
|
| 80 |
cache_examples=False,
|
| 81 |
-
run_on_click=True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
)
|
| 83 |
|
| 84 |
-
#
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
inp.change(fn=generate_static_badge, inputs=inputs, outputs=[out_code, out_preview])
|
| 88 |
|
| 89 |
-
# ์คํ
|
| 90 |
if __name__ == "__main__":
|
| 91 |
demo.launch()
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
# ---------------------------
|
| 5 |
+
# Badge URL generation
|
| 6 |
# ---------------------------
|
| 7 |
def generate_static_badge(label, message, color, label_color, logo, logo_color, style, link):
|
| 8 |
base = "https://img.shields.io/static/v1"
|
|
|
|
| 36 |
return html_code, badge_preview
|
| 37 |
|
| 38 |
# ---------------------------
|
| 39 |
+
# Gradio UI
|
| 40 |
# ---------------------------
|
| 41 |
with gr.Blocks(theme=gr.themes.Default()) as demo:
|
| 42 |
+
# Custom pastel CSS
|
| 43 |
gr.HTML("""
|
| 44 |
+
<style>
|
| 45 |
+
body { background: #f7f9fc; }
|
| 46 |
+
.gradio-container { background: #ffffff; border-radius: 16px; padding: 20px; }
|
| 47 |
+
.gr-button { background: #a8dadc !important; color: #1d3557 !important; }
|
| 48 |
+
.gr-textbox, .gr-select, .gr-color { background: #e8f6f3 !important; }
|
| 49 |
+
h1 { color: #457b9d; }
|
| 50 |
+
h3 { color: #6d6875; }
|
| 51 |
+
</style>
|
| 52 |
""")
|
| 53 |
|
| 54 |
+
gr.HTML("""
|
| 55 |
+
<h1 style=\"text-align:center; margin-bottom:0.2em;\">๐จ BadgeCraft</h1>
|
| 56 |
+
<p style=\"text-align:center; color:#555;\">Create colorful shields.io badges with live preview and HTML snippet.</p>
|
| 57 |
+
""")
|
| 58 |
+
|
| 59 |
+
# Output components
|
| 60 |
+
with gr.Row():
|
| 61 |
+
out_code = gr.Code(label="HTML Snippet", language="html")
|
| 62 |
+
out_preview = gr.HTML(label="Badge Preview")
|
| 63 |
|
| 64 |
+
# Input components with Discord defaults
|
| 65 |
with gr.Row():
|
| 66 |
+
label = gr.Textbox(label="Label", placeholder="e.g. build", value="Discord")
|
| 67 |
+
message = gr.Textbox(label="Message", placeholder="e.g. passing", value="Join our community")
|
| 68 |
+
logo = gr.Textbox(label="Logo", placeholder="e.g. github", value="discord")
|
| 69 |
with gr.Row():
|
| 70 |
+
color = gr.ColorPicker(label="Color", value="#7289DA")
|
| 71 |
+
label_color = gr.ColorPicker(label="Label Color", value="#99AAB5")
|
| 72 |
+
logo_color = gr.ColorPicker(label="Logo Color", value="white")
|
| 73 |
+
style = gr.Dropdown(label="Style", choices=["flat","flat-square","plastic","for-the-badge","social"], value="for-the-badge")
|
| 74 |
+
link = gr.Textbox(label="Link (URL)", placeholder="https://example.com", value="https://discord.gg/openfreeai")
|
| 75 |
|
| 76 |
+
# Example presets (click to autofill)
|
| 77 |
examples = [
|
| 78 |
+
["Discord","Join our community","#7289DA","#99AAB5","discord","white","for-the-badge","https://discord.gg/openfreeai"],
|
| 79 |
+
["X.com","Follow us","#1DA1F2","#A8D0E6","X","white","for-the-badge","https://x.com/openfree_ai"],
|
| 80 |
+
["Collections","Explore","#F9A826","#FBF3A1","huggingface","black","for-the-badge","https://huggingface.co/collections/VIDraft/best-open-ai-services-68057e6e312880ea92abaf4c"],
|
| 81 |
+
["GitHub","Star us","#181717","#B0B0B0","github","white","for-the-badge","https://github.com/openfreeai"],
|
| 82 |
+
["YouTube","Watch now","#FF0000","#FFA3A3","youtube","white","for-the-badge","https://www.youtube.com/@AITechTree"],
|
| 83 |
+
["Facebook","Like us","#1877F2","#A3C4F0","facebook","white","for-the-badge","https://www.facebook.com/profile.php?id=61575353674679"],
|
| 84 |
+
["Instagram","Follow","#E4405F","#F5A3B1","instagram","white","for-the-badge","https://www.instagram.com/openfree_ai/"],
|
| 85 |
+
["Threads","Join the convo","#000000","#CCCCCC","threads","white","for-the-badge","https://www.threads.net/@openfree_ai"],
|
| 86 |
]
|
| 87 |
+
gr.HTML("<h3 style='text-align:center; margin-top:20px;'>โจ Examples (click to autofill)</h3>")
|
| 88 |
gr.Examples(
|
| 89 |
examples=examples,
|
| 90 |
+
inputs=[label,message,color,label_color,logo,logo_color,style,link],
|
| 91 |
+
outputs=[out_code,out_preview],
|
| 92 |
fn=generate_static_badge,
|
| 93 |
cache_examples=False,
|
| 94 |
+
run_on_click=True
|
| 95 |
+
)
|
| 96 |
+
|
| 97 |
+
# On-load default preview
|
| 98 |
+
demo.load(
|
| 99 |
+
fn=generate_static_badge,
|
| 100 |
+
inputs=[label,message,color,label_color,logo,logo_color,style,link],
|
| 101 |
+
outputs=[out_code,out_preview]
|
| 102 |
)
|
| 103 |
|
| 104 |
+
# Live update on change
|
| 105 |
+
for inp in [label,message,color,label_color,logo,logo_color,style,link]:
|
| 106 |
+
inp.change(fn=generate_static_badge, inputs=[label,message,color,label_color,logo,logo_color,style,link], outputs=[out_code,out_preview])
|
|
|
|
| 107 |
|
|
|
|
| 108 |
if __name__ == "__main__":
|
| 109 |
demo.launch()
|