fantos commited on
Commit
d27a225
ยท
verified ยท
1 Parent(s): d64466a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -38
app.py CHANGED
@@ -23,11 +23,13 @@ def generate_static_badge(label, message, color, label_color, logo, logo_color,
23
  params.append(f"style={urllib.parse.quote(style, safe='')}")
24
 
25
  badge_url = base + ("?" + "&".join(params) if params else "")
 
26
  if link:
27
  html_code = f'<a href="{link}" target="_blank"><img src="{badge_url}" alt="badge"></a>'
28
  else:
29
  html_code = f'<img src="{badge_url}" alt="badge">'
30
 
 
31
  badge_preview = f"""
32
  <div style='padding:20px; background: #fefefe; border-radius: 12px; display: flex; justify-content: center;'>
33
  {html_code}
@@ -39,76 +41,91 @@ def generate_static_badge(label, message, color, label_color, logo, logo_color,
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
  with gr.Row():
48
  out_code = gr.Code(label="HTML Snippet", language="html")
49
  out_preview = gr.HTML(label="Badge Preview")
50
 
 
51
  with gr.Row():
52
  label = gr.Textbox(label="Label", placeholder="์˜ˆ: build")
53
  message = gr.Textbox(label="Message", placeholder="์˜ˆ: passing")
54
  logo = gr.Textbox(label="Logo", placeholder="์˜ˆ: github")
55
 
 
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
 
 
61
  style = gr.Dropdown(label="Style", choices=["flat", "flat-square", "plastic", "for-the-badge", "social"], value="for-the-badge")
62
  link = gr.Textbox(label="Link (๋ฐฐ์ง€ ํด๋ฆญ ์‹œ ์ด๋™ํ•  URL)", placeholder="https://yourlink.com")
63
 
 
64
  inputs = [label, message, color, label_color, logo, logo_color, style, link]
65
  for inp in inputs:
66
  inp.change(fn=generate_static_badge, inputs=inputs, outputs=[out_code, out_preview])
67
 
68
- def fill_example(label_val, message_val, logo_val, link_val):
 
69
  return label_val, message_val, logo_val, link_val
70
 
 
71
  gr.HTML("""
72
  <h3 style="text-align: center; margin-top: 30px;">โœจ Examples (Click to Load)</h3>
73
  """)
74
 
 
75
  with gr.Row():
76
- with gr.Column():
77
- gr.Button("Discord Badge Example").click(
78
- fn=fill_example,
79
- inputs=[],
80
- outputs=[label, message, logo, link],
81
- _js="() => window.open('https://discord.gg/openfreeai', '_blank')"
82
- ).style(full_width=True)
83
-
84
- gr.Button("X Badge Example").click(
85
- fn=fill_example,
86
- inputs=[],
87
- outputs=[label, message, logo, link],
88
- _js="() => window.open('https://x.com/openfree_ai', '_blank')"
89
- ).style(full_width=True)
90
-
91
- gr.Button("Instagram Badge Example").click(
92
- fn=fill_example,
93
- inputs=[],
94
- outputs=[label, message, logo, link],
95
- _js="() => window.open('https://www.instagram.com/openfree_ai', '_blank')"
96
- ).style(full_width=True)
97
-
98
- gr.Button("Threads Badge Example").click(
99
- fn=fill_example,
100
- inputs=[],
101
- outputs=[label, message, logo, link],
102
- _js="() => window.open('https://www.threads.net/@openfree_ai', '_blank')"
103
- ).style(full_width=True)
104
-
105
- gr.Button("Facebook Badge Example").click(
106
- fn=fill_example,
107
- inputs=[],
108
- outputs=[label, message, logo, link],
109
- _js="() => window.open('https://www.facebook.com/profile.php?id=61575353674679', '_blank')"
110
- ).style(full_width=True)
111
-
112
- # ์‹คํ–‰
 
 
 
 
 
 
113
  if __name__ == "__main__":
114
  demo.launch()
 
23
  params.append(f"style={urllib.parse.quote(style, safe='')}")
24
 
25
  badge_url = base + ("?" + "&".join(params) if params else "")
26
+ # HTML snippet with optional link wrapper
27
  if link:
28
  html_code = f'<a href="{link}" target="_blank"><img src="{badge_url}" alt="badge"></a>'
29
  else:
30
  html_code = f'<img src="{badge_url}" alt="badge">'
31
 
32
+ # Badge preview container
33
  badge_preview = f"""
34
  <div style='padding:20px; background: #fefefe; border-radius: 12px; display: flex; justify-content: center;'>
35
  {html_code}
 
41
  # Gradio UI ๊ตฌ์„ฑ
42
  # ---------------------------
43
  with gr.Blocks(theme=gr.themes.Default()) as demo:
44
+ # ์„œ๋น„์Šค ์ œ๋ชฉ ๋ฐ ์„ค๋ช…
45
  gr.HTML("""
46
  <h1 style="text-align: center; font-size: 2.2em; margin-bottom: 0.2em;">๐ŸŽจ BadgeCraft - Beautiful Badge Generator</h1>
47
  <p style="text-align: center; font-size: 1.1em; color: #555;">Design stylish shields.io badges with live preview and HTML snippet generation.</p>
48
  """)
49
 
50
+ # ์ฝ”๋“œ์™€ ๋ฏธ๋ฆฌ๋ณด๊ธฐ ์ˆ˜ํ‰ ๋ฐฐ์น˜
51
  with gr.Row():
52
  out_code = gr.Code(label="HTML Snippet", language="html")
53
  out_preview = gr.HTML(label="Badge Preview")
54
 
55
+ # ์‚ฌ์šฉ์ž ์ž…๋ ฅ ํผ: Label, Message, Logo
56
  with gr.Row():
57
  label = gr.Textbox(label="Label", placeholder="์˜ˆ: build")
58
  message = gr.Textbox(label="Message", placeholder="์˜ˆ: passing")
59
  logo = gr.Textbox(label="Logo", placeholder="์˜ˆ: github")
60
 
61
+ # ์ƒ‰์ƒ ํŒ”๋ ˆํŠธ: Color, Label Color, Logo Color
62
  with gr.Row():
63
  color = gr.ColorPicker(label="Color", value="#a0c4ff")
64
  label_color = gr.ColorPicker(label="Label Color", value="#bdb2ff")
65
  logo_color = gr.ColorPicker(label="Logo Color", value="#ffc6ff")
66
 
67
+ # Style ๋“œ๋กญ๋‹ค์šด ๋ฐ ๋งํฌ ์ž…๋ ฅ
68
  style = gr.Dropdown(label="Style", choices=["flat", "flat-square", "plastic", "for-the-badge", "social"], value="for-the-badge")
69
  link = gr.Textbox(label="Link (๋ฐฐ์ง€ ํด๋ฆญ ์‹œ ์ด๋™ํ•  URL)", placeholder="https://yourlink.com")
70
 
71
+ # ์ž…๋ ฅ๊ฐ’ ๋ณ€๊ฒฝ ์‹œ ์ž๋™ ์—…๋ฐ์ดํŠธ
72
  inputs = [label, message, color, label_color, logo, logo_color, style, link]
73
  for inp in inputs:
74
  inp.change(fn=generate_static_badge, inputs=inputs, outputs=[out_code, out_preview])
75
 
76
+ # ์˜ˆ์ œ ๋กœ๋”ฉ ํ•จ์ˆ˜
77
+ def load_example(label_val, message_val, logo_val, link_val):
78
  return label_val, message_val, logo_val, link_val
79
 
80
+ # Examples ๋ผ๋ฒจ
81
  gr.HTML("""
82
  <h3 style="text-align: center; margin-top: 30px;">โœจ Examples (Click to Load)</h3>
83
  """)
84
 
85
+ # ์˜ˆ์ œ ๋ฒ„ํŠผ๋“ค์„ ํ•œ ์ค„์— ๋ฐฐ์น˜
86
  with gr.Row():
87
+ discord_btn = gr.Button("Discord Badge Example")
88
+ x_btn = gr.Button("X Badge Example")
89
+ instagram_btn = gr.Button("Instagram Badge Example")
90
+ threads_btn = gr.Button("Threads Badge Example")
91
+ facebook_btn = gr.Button("Facebook Badge Example")
92
+
93
+ # ๊ฐ ๋ฒ„ํŠผ ํด๋ฆญ ์‹œ ์˜ˆ์ œ ๋ฐ์ดํ„ฐ ๋กœ๋“œ ๋ฐ ์ƒˆํƒญ ์—ด๊ธฐ
94
+ discord_btn.click(
95
+ fn=lambda: load_example("Discord", "Join", "discord", "https://discord.gg/openfreeai"),
96
+ inputs=[], outputs=[label, message, logo, link]
97
+ ).then(
98
+ lambda: gr.open_url("https://discord.gg/openfreeai"), [], []
99
+ )
100
+
101
+ x_btn.click(
102
+ fn=lambda: load_example("X.com", "Follow", "x", "https://x.com/openfree_ai"),
103
+ inputs=[], outputs=[label, message, logo, link]
104
+ ).then(
105
+ lambda: gr.open_url("https://x.com/openfree_ai"), [], []
106
+ )
107
+
108
+ instagram_btn.click(
109
+ fn=lambda: load_example("Instagram", "Follow", "instagram", "https://www.instagram.com/openfree_ai"),
110
+ inputs=[], outputs=[label, message, logo, link]
111
+ ).then(
112
+ lambda: gr.open_url("https://www.instagram.com/openfree_ai"), [], []
113
+ )
114
+
115
+ threads_btn.click(
116
+ fn=lambda: load_example("Threads", "Follow", "threads", "https://www.threads.net/@openfree_ai"),
117
+ inputs=[], outputs=[label, message, logo, link]
118
+ ).then(
119
+ lambda: gr.open_url("https://www.threads.net/@openfree_ai"), [], []
120
+ )
121
+
122
+ facebook_btn.click(
123
+ fn=lambda: load_example("Facebook", "Like", "facebook", "https://www.facebook.com/profile.php?id=61575353674679"),
124
+ inputs=[], outputs=[label, message, logo, link]
125
+ ).then(
126
+ lambda: gr.open_url("https://www.facebook.com/profile.php?id=61575353674679"), [], []
127
+ )
128
+
129
+ # ์•ฑ ์‹คํ–‰
130
  if __name__ == "__main__":
131
  demo.launch()