fantos commited on
Commit
98acb26
Β·
verified Β·
1 Parent(s): 4b15de6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -34
app.py CHANGED
@@ -2,7 +2,7 @@ import urllib.parse
2
  import gradio as gr
3
 
4
  # ---------------------------
5
- # λ°°μ§€ URL 생성 ν•¨μˆ˜ μ •μ˜
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
- <h1 style="text-align: center; font-size: 2.2em; margin-bottom: 0.2em;">🎨 BadgeCraft - Beautiful Badge Generator</h1>
44
- <p style="text-align: center; font-size: 1.1em; color: #555;">Design stylish shields.io badges with live preview and HTML snippet generation.</p>
 
 
 
 
 
 
45
  """)
46
 
47
- # 좜λ ₯ μ»΄ν¬λ„ŒνŠΈ
48
- out_code = gr.Code(label="HTML Snippet", language="html")
49
- out_preview = gr.HTML(label="Badge Preview")
 
 
 
 
 
 
50
 
51
- # μž…λ ₯ μ»΄ν¬λ„ŒνŠΈ
52
  with gr.Row():
53
- label = gr.Textbox(label="Label", placeholder="예: build")
54
- message = gr.Textbox(label="Message", placeholder="예: passing")
55
- logo = gr.Textbox(label="Logo", placeholder="예: github")
56
  with gr.Row():
57
- color = gr.ColorPicker(label="Color", value="#a0c4ff")
58
- label_color = gr.ColorPicker(label="Label Color", value="#bdb2ff")
59
- logo_color = gr.ColorPicker(label="Logo Color", value="#ffc6ff")
60
- style = gr.Dropdown(label="Style", choices=["flat", "flat-square", "plastic", "for-the-badge", "social"], value="for-the-badge")
61
- link = gr.Textbox(label="Link (λ°°μ§€ 클릭 μ‹œ 이동할 URL)", placeholder="https://yourlink.com")
62
 
63
- # Examples μ •μ˜ (8개 ν•„λ“œ μˆœμ„œλŒ€λ‘œ)
64
  examples = [
65
- ["Discord", "OpenFree AI", "OpenFree AI", "", "discord", "white", "for-the-badge", "https://discord.gg/openfreeai"],
66
- ["X.com", "OpenFree AI", "OpenFree AI", "", "X", "white", "for-the-badge", "https://x.com/openfree_ai"],
67
- ["Collections", "OpenFree AI", "", "", "huggingface", "black", "for-the-badge", "https://huggingface.co/collections/VIDraft/best-open-ai-services-68057e6e312880ea92abaf4c"],
68
- ["GitHub", "OpenFree AI", "", "", "github", "white", "for-the-badge", "https://github.com/openrunai"],
69
- ["YouTube", "λ‚˜μ˜ 유튜브 채널", "#FF0000", "", "youtube", "white", "for-the-badge", "https://www.youtube.com/@AITechTree"],
70
- ["Facebook", "OpenFree AI", "", "", "Facebook", "black", "for-the-badge", "https://www.facebook.com/profile.php?id=61575353674679"],
71
- ["Instagram", "OpenFree AI", "", "", "Instagram", "white", "for-the-badge", "https://www.instagram.com/openfree_ai/"],
72
- ["Threads", "δ½ ε₯½", "#FF0000", "", "Threads", "white", "for-the-badge", "https://www.threads.net/@openfree_ai"],
73
  ]
74
- gr.HTML("<h3 style='text-align:center; margin-top:20px;'>✨ Examples (ν΄λ¦­ν•˜λ©΄ μžλ™ μž…λ ₯)</h3>")
75
  gr.Examples(
76
  examples=examples,
77
- inputs=[label, message, color, label_color, logo, logo_color, style, link],
78
- outputs=[out_code, out_preview],
79
  fn=generate_static_badge,
80
  cache_examples=False,
81
- run_on_click=True,
 
 
 
 
 
 
 
82
  )
83
 
84
- # μ‹€μ‹œκ°„ change 이벀트 바인딩
85
- inputs = [label, message, color, label_color, logo, logo_color, style, link]
86
- for inp in inputs:
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()