openfree commited on
Commit
dd9c631
Β·
verified Β·
1 Parent(s): 07f7a33

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +342 -259
app.py CHANGED
@@ -1,336 +1,419 @@
1
- # ==========================================================
2
- # BadgeCraft ‑ Shields.io Badge Generator
3
- # β€’ ColorPicker μ‹€μ‹œκ°„ 반영 (.input 이벀트)
4
- # β€’ CDN μΊμ‹œ 무λ ₯ν™” ( _ts=<epoch> νŒŒλΌλ―Έν„° )
5
- # ==========================================================
6
  import urllib.parse
7
- import time
8
- import json
9
  import gradio as gr
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
- # ----------------------------------------------------------
13
- # 1) Badge URL 생성 ν•¨μˆ˜
14
- # ----------------------------------------------------------
15
- def generate_static_badge(label, message,
16
- color, label_color,
17
- logo, logo_color,
18
- style, link):
19
- """Shields.io badge URL κ³Ό HTML / 미리보기 μΉ΄λ“œ λ°˜ν™˜"""
20
-
21
- # ── β‘  HEX μ•žμ˜ # 제거 ───────────────────────────────
22
- strip = lambda c: c.lstrip("#") if isinstance(c, str) else c
23
- color, label_color, logo_color = map(strip, (color, label_color, logo_color))
24
-
25
- # ── β‘‘ 쿼리 νŒŒλΌλ―Έν„° 쑰립 + μΊμ‹œ λ²„μŠ€ν„°(_ts) ─────────
26
- base = "https://img.shields.io/static/v1"
27
- qs = {
28
- "label": label,
29
- "message": message,
30
- "color": color,
31
- "labelColor": label_color,
32
- "logo": logo,
33
- "logoColor": logo_color,
34
- "style": style,
35
- "_ts": str(int(time.time())) # ← μΊμ‹œ 무λ ₯ν™”
36
- }
37
- query = "&".join(f"{k}={urllib.parse.quote(v, safe='')}"
38
- for k, v in qs.items() if v)
39
- badge_url = f"{base}?{query}"
40
-
41
- # ── β‘’ HTML μ½”λ“œ & 미리보기 ꡬ성 ────────────────────
42
- img_tag = f'<img src="{badge_url}" alt="badge">'
43
- html_code = f'<a href="{link}" target="_blank">{img_tag}</a>' if link else img_tag
44
- preview = (
45
- "<div style='padding:30px;text-align:center;"
46
- "border-radius:16px;background:linear-gradient(135deg,#f8f9fa,#e9ecef);"
47
- "box-shadow:0 6px 12px rgba(0,0,0,.05);'>"
48
- f"{html_code}</div>"
49
- )
50
- return html_code, preview
51
 
 
 
 
 
 
 
 
 
52
 
53
- # ----------------------------------------------------------
54
- # 2) Gradio UI
55
- # ----------------------------------------------------------
56
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
57
-
58
- # ---------- Global CSS ----------
59
  gr.HTML("""
60
  <style>
61
- body{
62
- background:linear-gradient(120deg,#f8f9fa,#e2eafc);
63
- font-family:'Poppins','Noto Sans KR',sans-serif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  }
65
- .gradio-container{
66
- background:rgba(255,255,255,.85);
67
- backdrop-filter:blur(10px);
68
- border-radius:20px;
69
- padding:24px;
70
- box-shadow:0 10px 30px rgba(0,0,0,.08);
71
- max-width:1000px;
72
- margin:0 auto;
73
  }
74
- .gr-button{
75
- background:linear-gradient(135deg,#a8dadc,#88c1e9)!important;
76
- color:#1d3557!important;
77
- border:none!important;
78
- border-radius:10px!important;
79
- font-weight:600!important;
80
- transition:all .3s ease!important;
81
- box-shadow:0 4px 10px rgba(138,198,209,.3)!important;
82
  }
83
- .gr-button:hover{
84
- transform:translateY(-2px)!important;
85
- box-shadow:0 6px 15px rgba(138,198,209,.4)!important;
86
  }
87
- .gr-textbox,.gr-select,.gr-color{
88
- background:#e8f6f3!important;
89
- border:2px solid #d9f0ea!important;
90
- border-radius:12px!important;
91
- transition:all .3s ease!important;
92
  }
93
- .gr-textbox:focus,.gr-select:focus,.gr-color:focus{
94
- border-color:#a8dadc!important;
95
- box-shadow:0 0 0 3px rgba(168,218,220,.25)!important;
 
96
  }
97
- label.block span{
98
- color:#457b9d!important;
99
- font-weight:600!important;
100
- font-size:1rem!important;
101
  }
102
- h1{
103
- color:#5e60ce;font-weight:800;letter-spacing:-.5px;
 
 
 
104
  }
105
- h3{color:#5e60ce;font-weight:600;}
106
- .footer{
107
- margin-top:30px;text-align:center;font-size:.9rem;color:#6d6875;
 
 
 
 
108
  }
109
- .badge-section{
110
- background:rgba(255,255,255,.7);
111
- border-radius:16px;
112
- padding:20px;
113
- box-shadow:0 4px 12px rgba(0,0,0,.03);
114
- margin-bottom:24px;
115
- border:1px solid rgba(230,240,255,.7);
116
  }
117
- .example-grid{
118
- display:grid;
119
- grid-template-columns:repeat(4,1fr);
120
- gap:16px;margin-top:20px;
 
 
 
 
121
  }
122
- .example-item{
123
- background:linear-gradient(135deg,#f1f8ff,#e8f4ff);
124
- border-radius:12px;padding:16px;text-align:center;
125
- cursor:pointer;transition:all .3s ease;border:2px solid transparent;
126
  }
127
- .example-item:hover{
128
- transform:translateY(-3px);
129
- box-shadow:0 8px 15px rgba(0,0,0,.05);
130
- border-color:#a8dadc;
 
 
 
 
 
 
 
 
 
 
 
 
 
131
  }
132
- @media(max-width:768px){.example-grid{grid-template-columns:repeat(2,1fr);} }
133
- @media(max-width:600px){.example-grid{grid-template-columns:1fr;} }
134
  </style>
135
  """)
136
 
137
- # ---------- Header ----------
138
  gr.HTML("""
139
- <div style="text-align:center;margin-bottom:24px;">
140
- <h1 style="font-size:2.8rem;margin-bottom:.2em;
141
- background:linear-gradient(90deg,#5e60ce,#64dfdf);
142
- -webkit-background-clip:text;-webkit-text-fill-color:transparent;">
143
- 🎨 BadgeCraft
144
  </h1>
145
- <p style="font-size:1.2rem;margin:.5em 0;color:#457b9d;max-width:700px;margin:0 auto;">
146
- Create beautiful badges with live preview and HTML snippet
147
  </p>
148
- <div style="margin-top:10px;display:flex;justify-content:center;gap:12px;flex-wrap:wrap;">
149
- <span style="display:inline-block;background:#e9f5db;color:#588157;
150
- padding:6px 12px;border-radius:30px;font-size:.9rem;">
151
- <strong>✨ MIT License</strong>
152
- </span>
153
- <span style="display:inline-block;background:#d8f3dc;color:#2d6a4f;
154
- padding:6px 12px;border-radius:30px;font-size:.9rem;">
155
- <strong>πŸ‘₯ Created by OpenFreeAI Team</strong>
156
- </span>
157
  </div>
158
- </div>
159
  """)
160
 
161
- # ---------- Tabs ----------
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
  with gr.Tabs():
163
- # β–·β–· Badge Generator
164
  with gr.TabItem("Badge Generator"):
165
-
166
- # ===== 쒌츑 μž…λ ₯ =====
167
  with gr.Row():
168
  with gr.Column():
169
  with gr.Group(elem_classes="badge-section"):
170
- gr.HTML("<h3 style='margin-top:0;margin-bottom:16px;font-size:1.3rem;'>✏️ Badge Settings</h3>")
171
- label = gr.Textbox(label="Label", value="Discord", lines=1, elem_id="label-input")
172
- message = gr.Textbox(label="Message", value="Join our community", lines=1, elem_id="message-input")
173
- logo = gr.Textbox(label="Logo", value="discord", lines=1, elem_id="logo-input")
174
- style = gr.Dropdown(label="Style",
175
- choices=["flat","flat-square","plastic","for-the-badge","social"],
176
- value="for-the-badge", elem_id="style-input")
177
- color = gr.ColorPicker(label="Background Color", value="#5865F2", elem_id="color-input")
178
- label_color = gr.ColorPicker(label="Label Background Color",value="#99AAFF", elem_id="label-color-input")
179
- logo_color = gr.ColorPicker(label="Logo Color", value="#ffffff", elem_id="logo-color-input")
180
- link = gr.Textbox(label="Link (URL)", value="https://discord.gg/openfreeai", lines=1, elem_id="link-input")
181
-
182
- # ===== 우츑 미리보기 / HTML =====
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
183
  with gr.Column():
184
  with gr.Group(elem_classes="badge-section"):
185
- gr.HTML("<h3 style='margin-top:0;margin-bottom:16px;font-size:1.3rem;'>πŸ‘οΈ Preview</h3>")
186
- out_preview = gr.HTML()
187
  with gr.Group(elem_classes="badge-section"):
188
- gr.HTML("<h3 style='margin-top:0;margin-bottom:16px;font-size:1.3rem;'>πŸ’» HTML Code</h3>")
189
- out_code = gr.Code(language="html", lines=3)
190
 
191
- # ===== 예제 데이터 & κ·Έλ¦¬λ“œ =====
192
  examples = [
193
- ["Discord","OpenfreeΒ AI","#5865F2","#99AAFF","discord","white","for-the-badge","https://discord.gg/openfreeai"],
194
- ["X.com","Follow us","#1DA1F2","#00CFFF","x","white","for-the-badge","https://x.com/openfree_ai"],
195
- ["Collections","Explore","#FFB300","#FFF176","huggingface","black","for-the-badge",
196
- "https://huggingface.co/collections/VIDraft/best-open-ai-services-68057e6e312880ea92abaf4c"],
197
- ["GitHub","Star us","#0A0A0A","#39FF14","github","white","for-the-badge","https://github.com/openfreeai"],
198
- ["YouTube","Watch now","#E50000","#FF5E5E","youtube","white","for-the-badge","https://www.youtube.com/@AITechTree"],
199
- ["Facebook","Like us","#1877F2","#6FAFFF","facebook","white","for-the-badge","https://www.facebook.com/profile.php?id=61575353674679"],
200
- ["Instagram","友情 萬世","#E4405F","#FF77A9","instagram","white","for-the-badge","https://www.instagram.com/openfree_ai/"],
201
- ["Threads","ν•¨κ»˜ μ¦κ²¨μš”.","#000000","#FF00FF","threads","white","for-the-badge","https://www.threads.net/@openfree_ai"],
202
  ]
203
 
204
- # 예제 κ·Έλ¦¬λ“œ HTML
205
  html_items = '<div class="example-grid">'
206
  for idx, ex in enumerate(examples):
207
- badge_url = "https://img.shields.io/static/v1?" + "&".join([
208
- f"label={urllib.parse.quote(ex[0], safe='')}",
209
- f"message={urllib.parse.quote(ex[1], safe='')}",
210
- f"color={urllib.parse.quote(ex[2].lstrip('#'), safe='')}",
211
- f"labelColor={urllib.parse.quote(ex[3].lstrip('#'), safe='')}",
212
- f"logo={urllib.parse.quote(ex[4], safe='')}",
213
- f"logoColor={urllib.parse.quote(ex[5], safe='')}",
214
- f"style={urllib.parse.quote(ex[6], safe='')}",
215
- ])
 
 
 
 
 
 
 
216
  html_items += f'''
217
  <div class="example-item" onclick="applyExample({idx})">
218
- <img src="{badge_url}" alt="{ex[0]} badge" style="margin-bottom:8px;">
219
- <div style="font-size:.9rem;color:#457b9d;">{ex[0]}</div>
220
  </div>
221
  '''
222
  html_items += '</div>'
223
 
224
- # -------- React‑controlled input hack & 예제 적용 JS --------
225
- hack_js = """
226
- function updateReactValue(el,val){
227
- if(!el)return;
228
- let proto=window.HTMLInputElement.prototype;
229
- if(el.tagName==="TEXTAREA")proto=window.HTMLTextAreaElement.prototype;
230
- const desc=Object.getOwnPropertyDescriptor(proto,"value");
231
- desc.set.call(el,val);
232
- el.dispatchEvent(new Event("input",{bubbles:true}));
233
- el.dispatchEvent(new Event("change",{bubbles:true}));
234
  }
235
- function toHexIfNeeded(c){
236
- if(!c)return"#000000";
237
- if(c.toLowerCase()==="white")return"#ffffff";
238
- if(c.toLowerCase()==="black")return"#000000";
239
- return c;
 
240
  }
241
- function setColor(elemId,val){
242
- const wrap=document.getElementById(elemId);
243
- if(!wrap)return;
244
- let input=wrap.querySelector("input[type='color']");
245
- if(!input)input=wrap.querySelector("input[type='text']");
246
- if(input)updateReactValue(input,val);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
247
  }
 
248
  """
249
 
250
- apply_example_js = (
251
- "<script>\n" + hack_js +
252
- "const examples=" + json.dumps(examples) + ";\n"
253
- "function applyExample(i){\n"
254
- " const ex=examples[i];\n"
255
- " updateReactValue(document.querySelector('#label-input textarea,#label-input input'),ex[0]);\n"
256
- " updateReactValue(document.querySelector('#message-input textarea,#message-input input'),ex[1]);\n"
257
- " setColor('color-input',toHexIfNeeded(ex[2]));\n"
258
- " setColor('label-color-input',toHexIfNeeded(ex[3]));\n"
259
- " updateReactValue(document.querySelector('#logo-input textarea,#logo-input input'),ex[4]);\n"
260
- " setColor('logo-color-input',toHexIfNeeded(ex[5]));\n"
261
- " const sel=document.querySelector('#style-input select');\n"
262
- " if(sel){sel.value=ex[6];sel.dispatchEvent(new Event('change',{bubbles:true}));}\n"
263
- " updateReactValue(document.querySelector('#link-input textarea,#link-input input'),ex[7]);\n"
264
- "}\n</script>"
265
- )
266
  gr.HTML(html_items + apply_example_js)
267
 
268
- # ===== 초기 λ‘œλ“œ & μ‹€μ‹œκ°„ μ—°κ²° =====
 
 
 
 
 
 
 
 
 
 
 
 
 
 
269
  demo.load(
270
- fn=generate_static_badge,
271
  inputs=[label, message, color, label_color, logo, logo_color, style, link],
272
  outputs=[out_code, out_preview]
273
  )
274
-
275
- # ── ν…μŠ€νŠΈ/λ“œλ‘­λ‹€μš΄: change 이벀트
276
- for comp in [label, message, logo, style, link]:
277
- comp.change(
278
- fn=generate_static_badge,
279
- inputs=[label, message, color, label_color, logo, logo_color, style, link],
280
- outputs=[out_code, out_preview]
281
- )
282
- # ── ColorPicker: input 이벀트
283
- for comp in [color, label_color, logo_color]:
284
- comp.input(
285
- fn=generate_static_badge,
286
  inputs=[label, message, color, label_color, logo, logo_color, style, link],
287
  outputs=[out_code, out_preview]
288
  )
289
 
290
- # β–·β–· Help νƒ­
291
  with gr.TabItem("Help"):
292
  gr.HTML('''
293
- <div style="padding:20px;background:rgba(255,255,255,.7);
294
- border-radius:16px;box-shadow:0 4px 12px rgba(0,0,0,.03);">
295
- <h3 style="color:#5e60ce;margin-top:0;">πŸ“‹ How to Use BadgeCraft</h3>
296
- <h4 style="color:#457b9d;margin-bottom:8px;">✨ What are Badges?</h4>
297
- <p>Badges are small visual indicators that can be used in README files, websites, and documentation. Shields.io badges display project status, social links, version info, and more.</p>
298
- <h4 style="color:#457b9d;margin-bottom:8px;">πŸ› οΈ Basic Settings</h4>
299
- <ul>
300
- <li><strong>Label</strong>: Text on the left side (e.g., "Discord")</li>
301
- <li><strong>Message</strong>: Text on the right side</li>
302
- <li><strong>Logo</strong>: A Simple‑Icons name (<a href="https://simpleicons.org" target="_blank">List</a>)</li>
303
- <li><strong>Style</strong>: Badge shape (flat, plastic, for‑the‑badge …)</li>
304
- </ul>
305
- <h4 style="color:#457b9d;margin-bottom:8px;">🎨 Color Settings</h4>
306
- <ul>
307
- <li><strong>Background Color</strong>: right‑side color</li>
308
- <li><strong>Label Background Color</strong>: left‑side color</li>
309
- <li><strong>Logo Color</strong>: logo tint (white / black / #HEX)</li>
310
- </ul>
311
- <h4 style="color:#457b9d;margin-bottom:8px;">πŸ”— Using the HTML</h4>
312
- <p>Copy the generated HTML and paste it into your site, blog, or GitHubΒ README.<br>
313
- GitHub also accepts raw Markdown: <code>![alt](badgeURL)</code></p>
314
- <h4 style="color:#457b9d;margin-bottom:8px;">πŸ’‘ Tips</h4>
315
- <ul>
316
- <li>Click any example tile to auto‑fill all fields</li>
317
- <li>Preview refreshes live as you type or pick colors</li>
318
- <li>Over 2Β 000 Simple‑Icons logos are supported</li>
319
- </ul>
320
  </div>
321
  ''')
322
 
323
- # ---------- Footer ----------
324
  gr.HTML('''
325
  <div class="footer">
326
- <p>© 2023‑2025Β BadgeCraftΒ |Β MITΒ LicenseΒ |Β 
327
- <a href="https://discord.gg/openfreeai" target="_blank" style="color:#5e60ce;">Discord</a>
328
- </p>
329
  </div>
330
  ''')
331
 
332
- # ----------------------------------------------------------
333
- # 3) Launch
334
- # ----------------------------------------------------------
335
  if __name__ == "__main__":
336
- demo.launch()
 
 
 
 
 
 
1
  import urllib.parse
 
 
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"
9
+ params = []
10
+ if label:
11
+ params.append(f"label={urllib.parse.quote(label, safe='')}")
12
+ if message:
13
+ params.append(f"message={urllib.parse.quote(message, safe='')}")
14
+ if color:
15
+ params.append(f"color={urllib.parse.quote(color, safe='')}")
16
+ if label_color:
17
+ params.append(f"labelColor={urllib.parse.quote(label_color, safe='')}")
18
+ if logo:
19
+ params.append(f"logo={urllib.parse.quote(logo, safe='')}")
20
+ if logo_color:
21
+ params.append(f"logoColor={urllib.parse.quote(logo_color, safe='')}")
22
+ if style:
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:30px; background: linear-gradient(135deg, #f8f9fa, #e9ecef);
33
+ border-radius: 16px; display: flex; justify-content: center;
34
+ box-shadow: 0 6px 12px rgba(0,0,0,0.05);'>
35
+ {html_code}
36
+ </div>
37
+ """
38
+ return html_code, badge_preview
39
 
40
+ # ---------------------------
41
+ # Gradio UI
42
+ # ---------------------------
43
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
44
+ # Custom CSS
 
45
  gr.HTML("""
46
  <style>
47
+ body {
48
+ background: linear-gradient(120deg, #f8f9fa, #e2eafc);
49
+ font-family: 'Poppins', 'Noto Sans KR', sans-serif;
50
+ }
51
+ .gradio-container {
52
+ background: rgba(255, 255, 255, 0.85);
53
+ backdrop-filter: blur(10px);
54
+ border-radius: 20px;
55
+ padding: 24px;
56
+ box-shadow: 0 10px 30px rgba(0,0,0,0.08);
57
+ max-width: 1000px;
58
+ margin: 0 auto;
59
+ }
60
+ .gr-button {
61
+ background: linear-gradient(135deg, #a8dadc, #88c1e9) !important;
62
+ color: #1d3557 !important;
63
+ border: none !important;
64
+ border-radius: 10px !important;
65
+ font-weight: 600 !important;
66
+ transition: all 0.3s ease !important;
67
+ box-shadow: 0 4px 10px rgba(138, 198, 209, 0.3) !important;
68
  }
69
+ .gr-button:hover {
70
+ transform: translateY(-2px) !important;
71
+ box-shadow: 0 6px 15px rgba(138, 198, 209, 0.4) !important;
 
 
 
 
 
72
  }
73
+ .gr-textbox, .gr-select, .gr-color {
74
+ background: #e8f6f3 !important;
75
+ border: 2px solid #d9f0ea !important;
76
+ border-radius: 12px !important;
77
+ transition: all 0.3s ease !important;
 
 
 
78
  }
79
+ .gr-textbox:focus, .gr-select:focus, .gr-color:focus {
80
+ border-color: #a8dadc !important;
81
+ box-shadow: 0 0 0 3px rgba(168, 218, 220, 0.25) !important;
82
  }
83
+ label.block span {
84
+ color: #457b9d !important;
85
+ font-weight: 600 !important;
86
+ font-size: 1rem !important;
 
87
  }
88
+ h1 {
89
+ color: #5e60ce;
90
+ font-weight: 800;
91
+ letter-spacing: -0.5px;
92
  }
93
+ h3 {
94
+ color: #5e60ce;
95
+ font-weight: 600;
 
96
  }
97
+ .footer {
98
+ margin-top: 30px;
99
+ text-align: center;
100
+ font-size: 0.9rem;
101
+ color: #6d6875;
102
  }
103
+ .badge-section {
104
+ background: rgba(255, 255, 255, 0.7);
105
+ border-radius: 16px;
106
+ padding: 20px;
107
+ box-shadow: 0 4px 12px rgba(0,0,0,0.03);
108
+ margin-bottom: 24px;
109
+ border: 1px solid rgba(230, 240, 255, 0.7);
110
  }
111
+ .example-grid {
112
+ display: grid;
113
+ grid-template-columns: repeat(4, 1fr);
114
+ grid-template-rows: repeat(2, auto);
115
+ gap: 16px;
116
+ margin-top: 20px;
 
117
  }
118
+ .example-item {
119
+ background: linear-gradient(135deg, #f1f8ff, #e8f4ff);
120
+ border-radius: 12px;
121
+ padding: 16px;
122
+ text-align: center;
123
+ cursor: pointer;
124
+ transition: all 0.3s ease;
125
+ border: 2px solid transparent;
126
  }
127
+ .example-item:hover {
128
+ transform: translateY(-3px);
129
+ box-shadow: 0 8px 15px rgba(0,0,0,0.05);
130
+ border-color: #a8dadc;
131
  }
132
+ @media (max-width: 768px) {
133
+ .example-grid {
134
+ grid-template-columns: repeat(2, 1fr);
135
+ }
136
+ }
137
+ @media (max-width: 600px) {
138
+ .example-grid {
139
+ grid-template-columns: 1fr;
140
+ }
141
+ }
142
+ .color-preview {
143
+ display: inline-block;
144
+ width: 20px;
145
+ height: 20px;
146
+ margin-right: 5px;
147
+ border-radius: 4px;
148
+ vertical-align: middle;
149
  }
 
 
150
  </style>
151
  """)
152
 
153
+ # Header section
154
  gr.HTML("""
155
+ <div style="text-align:center; margin-bottom:24px;">
156
+ <h1 style="font-size:2.8rem; margin-bottom:0.2em; background: linear-gradient(90deg, #5e60ce, #64dfdf); -webkit-background-clip: text; -webkit-text-fill-color: transparent;">
157
+ 🎨 BadgeCraft
 
 
158
  </h1>
159
+ <p style="font-size:1.2rem; margin:0.5em 0; color:#457b9d; max-width:700px; margin:0 auto;">
160
+ Create beautiful badges with live preview and HTML snippet
161
  </p>
162
+ <div style="margin-top:10px; display:flex; justify-content:center; gap:12px; flex-wrap:wrap;">
163
+ <span style="display:inline-block; background:#e9f5db; color:#588157; padding:6px 12px; border-radius:30px; font-size:0.9rem;">
164
+ <strong>✨ MIT License</strong>
165
+ </span>
166
+ <span style="display:inline-block; background:#d8f3dc; color:#2d6a4f; padding:6px 12px; border-radius:30px; font-size:0.9rem;">
167
+ <strong>πŸ‘₯ Created by OpenFreeAI Team</strong>
168
+ </span>
 
 
169
  </div>
170
+ </div>
171
  """)
172
 
173
+ # Define color options
174
+ color_options = {
175
+ "Red": "#ff0000",
176
+ "Blue": "#0000ff",
177
+ "Green": "#00ff00",
178
+ "Yellow": "#ffff00",
179
+ "Purple": "#800080",
180
+ "Orange": "#ffa500",
181
+ "Pink": "#ffc0cb",
182
+ "Teal": "#008080",
183
+ "Navy": "#000080",
184
+ "Lime": "#00ff00",
185
+ "Cyan": "#00ffff",
186
+ "Magenta": "#ff00ff",
187
+ "Gold": "#ffd700",
188
+ "Silver": "#c0c0c0"
189
+ }
190
+
191
  with gr.Tabs():
 
192
  with gr.TabItem("Badge Generator"):
 
 
193
  with gr.Row():
194
  with gr.Column():
195
  with gr.Group(elem_classes="badge-section"):
196
+ gr.HTML("<h3 style='margin-top:0; margin-bottom:16px; font-size:1.3rem;'>✏️ Badge Settings</h3>")
197
+ label = gr.Textbox(label="Label", value="Discord", elem_id="label-input", lines=1)
198
+ message = gr.Textbox(label="Message", value="Join our community", elem_id="message-input", lines=1)
199
+ logo = gr.Textbox(label="Logo", value="discord", elem_id="logo-input", lines=1)
200
+ style = gr.Dropdown(
201
+ label="Style",
202
+ choices=["flat", "flat-square", "plastic", "for-the-badge", "social"],
203
+ value="for-the-badge",
204
+ elem_id="style-input"
205
+ )
206
+
207
+ # Replace color pickers with dropdown selections
208
+ color_choices = [f"<div><span class='color-preview' style='background-color:{hex_code}'></span>{name}</div>" for name, hex_code in color_options.items()]
209
+ color = gr.Dropdown(
210
+ label="Background Color",
211
+ choices=list(color_options.keys()),
212
+ value="Blue",
213
+ elem_id="color-input"
214
+ )
215
+ label_color = gr.Dropdown(
216
+ label="Label Background Color",
217
+ choices=list(color_options.keys()),
218
+ value="Purple",
219
+ elem_id="label-color-input"
220
+ )
221
+ logo_color = gr.Dropdown(
222
+ label="Logo Color",
223
+ choices=["white", "black"] + list(color_options.keys()),
224
+ value="white",
225
+ elem_id="logo-color-input"
226
+ )
227
+ link = gr.Textbox(label="Link (URL)", value="https://discord.gg/openfreeai", elem_id="link-input", lines=1)
228
  with gr.Column():
229
  with gr.Group(elem_classes="badge-section"):
230
+ gr.HTML("<h3 style='margin-top:0; margin-bottom:16px; font-size:1.3rem;'>πŸ‘οΈ Preview</h3>")
231
+ out_preview = gr.HTML(label="")
232
  with gr.Group(elem_classes="badge-section"):
233
+ gr.HTML("<h3 style='margin-top:0; margin-bottom:16px; font-size:1.3rem;'>πŸ’» HTML Code</h3>")
234
+ out_code = gr.Code(label="", language="html", lines=3)
235
 
236
+ # 예제 리슀트 (label, message, bg_color, label_color, logo, logo_color, style, link)
237
  examples = [
238
+ ["Discord", "Openfree AI", "Blue", "Purple", "discord", "white", "for-the-badge", "https://discord.gg/openfreeai"],
239
+ ["X.com", "Follow us", "Blue", "Cyan", "x", "white", "for-the-badge", "https://x.com/openfree_ai"],
240
+ ["Collections","Explore", "Orange", "Yellow", "huggingface","black","for-the-badge", "https://huggingface.co/collections/VIDraft/best-open-ai-services-68057e6e312880ea92abaf4c"],
241
+ ["GitHub", "Star us", "Navy", "Lime", "github", "white", "for-the-badge", "https://github.com/openfreeai"],
242
+ ["YouTube", "Watch now", "Red", "Orange", "youtube", "white", "for-the-badge", "https://www.youtube.com/@AITechTree"],
243
+ ["Facebook", "Like us", "Blue", "Cyan", "facebook", "white", "for-the-badge", "https://www.facebook.com/profile.php?id=61575353674679"],
244
+ ["Instagram", "友情 萬世", "Magenta", "Pink", "instagram", "white", "for-the-badge", "https://www.instagram.com/openfree_ai/"],
245
+ ["Threads", "ν•¨κ»˜ μ¦κ²¨μš”.", "Navy", "Magenta", "threads", "white", "for-the-badge", "https://www.threads.net/@openfree_ai"],
 
246
  ]
247
 
248
+ # 예제 미리보기
249
  html_items = '<div class="example-grid">'
250
  for idx, ex in enumerate(examples):
251
+ # ex = [label, message, bg_color, label_color, logo, logo_color, style, link]
252
+ color_hex = color_options.get(ex[2], ex[2])
253
+ label_color_hex = color_options.get(ex[3], ex[3])
254
+ logo_color_val = color_options.get(ex[5], ex[5]) if ex[5] in color_options else ex[5]
255
+
256
+ badge_url = (
257
+ "https://img.shields.io/static/v1?" + "&".join([
258
+ f"label={urllib.parse.quote(ex[0], safe='')}",
259
+ f"message={urllib.parse.quote(ex[1], safe='')}",
260
+ f"color={urllib.parse.quote(color_hex, safe='')}",
261
+ f"labelColor={urllib.parse.quote(label_color_hex, safe='')}",
262
+ f"logo={urllib.parse.quote(ex[4], safe='')}",
263
+ f"logoColor={urllib.parse.quote(logo_color_val, safe='')}",
264
+ f"style={urllib.parse.quote(ex[6], safe='')}"
265
+ ])
266
+ )
267
  html_items += f'''
268
  <div class="example-item" onclick="applyExample({idx})">
269
+ <img src="{badge_url}" alt="{ex[0]} badge" style="margin-bottom:8px;">
270
+ <div style="font-size:0.9rem; color:#457b9d;">{ex[0]}</div>
271
  </div>
272
  '''
273
  html_items += '</div>'
274
 
275
+ # 예제λ₯Ό ν΄λ¦­ν–ˆμ„ λ•Œ μ μš©ν•˜λŠ” main ν•¨μˆ˜
276
+ apply_example_js = """
277
+ <script>
278
+ function updateSelectValue(selectEl, newValue) {
279
+ if (!selectEl) return;
280
+ selectEl.value = newValue;
281
+ selectEl.dispatchEvent(new Event("change", { bubbles: true }));
 
 
 
282
  }
283
+
284
+ function updateTextValue(el, newValue) {
285
+ if (!el) return;
286
+ el.value = newValue;
287
+ el.dispatchEvent(new Event("input", { bubbles: true }));
288
+ el.dispatchEvent(new Event("change", { bubbles: true }));
289
  }
290
+
291
+ const examples = """ + str(examples).replace("'", '"') + """;
292
+
293
+ function applyExample(i) {
294
+ const ex = examples[i];
295
+ // ex = [label, message, bg_color, label_color, logo, logo_color, style, link]
296
+
297
+ // Label
298
+ const labelBox = document.querySelector("#label-input textarea, #label-input input");
299
+ if (labelBox) {
300
+ updateTextValue(labelBox, ex[0]);
301
+ }
302
+
303
+ // Message
304
+ const msgBox = document.querySelector("#message-input textarea, #message-input input");
305
+ if (msgBox) {
306
+ updateTextValue(msgBox, ex[1]);
307
+ }
308
+
309
+ // Background Color (Dropdown)
310
+ const bgColorSelect = document.querySelector("#color-input select");
311
+ if (bgColorSelect) {
312
+ updateSelectValue(bgColorSelect, ex[2]);
313
+ }
314
+
315
+ // Label Background Color (Dropdown)
316
+ const labelColorSelect = document.querySelector("#label-color-input select");
317
+ if (labelColorSelect) {
318
+ updateSelectValue(labelColorSelect, ex[3]);
319
+ }
320
+
321
+ // Logo
322
+ const logoBox = document.querySelector("#logo-input textarea, #logo-input input");
323
+ if (logoBox) {
324
+ updateTextValue(logoBox, ex[4]);
325
+ }
326
+
327
+ // Logo Color (Dropdown)
328
+ const logoColorSelect = document.querySelector("#logo-color-input select");
329
+ if (logoColorSelect) {
330
+ updateSelectValue(logoColorSelect, ex[5]);
331
+ }
332
+
333
+ // Style (Dropdown)
334
+ const styleSelect = document.querySelector("#style-input select");
335
+ if (styleSelect) {
336
+ updateSelectValue(styleSelect, ex[6]);
337
+ }
338
+
339
+ // Link
340
+ const linkBox = document.querySelector("#link-input textarea, #link-input input");
341
+ if (linkBox) {
342
+ updateTextValue(linkBox, ex[7]);
343
+ }
344
  }
345
+ </script>
346
  """
347
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
348
  gr.HTML(html_items + apply_example_js)
349
 
350
+ # ν•¨μˆ˜λ₯Ό μˆ˜μ •ν•˜μ—¬ 색상 값을 λ³€ν™˜
351
+ def process_badge(label, message, color_name, label_color_name, logo, logo_color_name, style, link):
352
+ # 색상 이름을 hex μ½”λ“œλ‘œ λ³€ν™˜
353
+ color_hex = color_options.get(color_name, "#000000")
354
+ label_color_hex = color_options.get(label_color_name, "#000000")
355
+
356
+ # logo_colorκ°€ whiteλ‚˜ black인 경우 κ·ΈλŒ€λ‘œ μ‚¬μš©, μ•„λ‹ˆλ©΄ hex μ½”λ“œλ‘œ λ³€ν™˜
357
+ if logo_color_name in ["white", "black"]:
358
+ logo_color_hex = logo_color_name
359
+ else:
360
+ logo_color_hex = color_options.get(logo_color_name, "#ffffff")
361
+
362
+ return generate_static_badge(label, message, color_hex, label_color_hex, logo, logo_color_hex, style, link)
363
+
364
+ # 초기/μ‹€μ‹œκ°„ μ—…λ°μ΄νŠΈ
365
  demo.load(
366
+ fn=process_badge,
367
  inputs=[label, message, color, label_color, logo, logo_color, style, link],
368
  outputs=[out_code, out_preview]
369
  )
370
+ for inp in [label, message, color, label_color, logo, logo_color, style, link]:
371
+ inp.change(
372
+ fn=process_badge,
 
 
 
 
 
 
 
 
 
373
  inputs=[label, message, color, label_color, logo, logo_color, style, link],
374
  outputs=[out_code, out_preview]
375
  )
376
 
 
377
  with gr.TabItem("Help"):
378
  gr.HTML('''
379
+ <div style="padding: 20px; background: rgba(255, 255, 255, 0.7); border-radius: 16px; box-shadow: 0 4px 12px rgba(0,0,0,0.03);">
380
+ <h3 style="color: #5e60ce; margin-top:0;">πŸ“‹ How to Use BadgeCraft</h3>
381
+ <h4 style="color: #457b9d; margin-bottom: 8px;">✨ What are Badges?</h4>
382
+ <p>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.</p>
383
+ <h4 style="color: #457b9d; margin-bottom: 8px;">πŸ› οΈ Basic Settings</h4>
384
+ <ul>
385
+ <li><strong>Label</strong>: Text displayed on the left side of the badge (e.g., "Discord", "Version", "Status")</li>
386
+ <li><strong>Message</strong>: Text displayed on the right side of the badge</li>
387
+ <li><strong>Logo</strong>: Name of a logo provided by Simple Icons (<a href="https://simpleicons.org/" target="_blank">View List</a>)</li>
388
+ <li><strong>Style</strong>: Determines the shape of the badge (flat, plastic, for-the-badge, etc.)</li>
389
+ </ul>
390
+ <h4 style="color: #457b9d; margin-bottom: 8px;">🎨 ColorSettings</h4>
391
+ <ul>
392
+ <li><strong>Background Color</strong>: Background color for the right side of the badge</li>
393
+ <li><strong>Label Background Color</strong>: Background color for the left side of the badge</li>
394
+ <li><strong>Logo Color</strong>: Color of the logo (e.g. white or black)</li>
395
+ </ul>
396
+ <h4 style="color: #457b9d; margin-bottom: 8px;">πŸ”— Using the HTML</h4>
397
+ <p>Copy the generated HTML code and paste it into your website, blog, GitHub README, etc.</p>
398
+ <p>HTML works in GitHub READMEs, but if you prefer markdown, use <code>![alt text](badge URL)</code>.</p>
399
+ <h4 style="color: #457b9d; margin-bottom: 8px;">πŸ’‘ Tips</h4>
400
+ <ul>
401
+ <li>Click on any example in the grid to automatically fill in all settings</li>
402
+ <li>The preview updates in real-time as you make changes</li>
403
+ <li>You can use over 2000+ logos from Simple Icons - just enter the name</li>
404
+ <li>Choose from predefined colors in the dropdown menus for consistent results</li>
405
+ </ul>
406
  </div>
407
  ''')
408
 
409
+ # Footer
410
  gr.HTML('''
411
  <div class="footer">
412
+ <p>Β© 2023-2025 BadgeCraft | MIT License
413
+ <a href="https://discord.gg/openfreeai" target="_blank" style="color:#5e60ce;">Discord</a>
414
+ </p>
415
  </div>
416
  ''')
417
 
 
 
 
418
  if __name__ == "__main__":
419
+ demo.launch()