Update app.py
Browse files
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 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
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 |
-
#
|
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
|
63 |
-
font-family:'Poppins','Noto Sans KR',sans-serif;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
}
|
65 |
-
.
|
66 |
-
|
67 |
-
|
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-
|
75 |
-
background:
|
76 |
-
|
77 |
-
border:
|
78 |
-
|
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-
|
84 |
-
|
85 |
-
box-shadow:0
|
86 |
}
|
87 |
-
.
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
transition:all .3s ease!important;
|
92 |
}
|
93 |
-
|
94 |
-
|
95 |
-
|
|
|
96 |
}
|
97 |
-
|
98 |
-
color
|
99 |
-
font-weight:600
|
100 |
-
font-size:1rem!important;
|
101 |
}
|
102 |
-
|
103 |
-
|
|
|
|
|
|
|
104 |
}
|
105 |
-
|
106 |
-
|
107 |
-
|
|
|
|
|
|
|
|
|
108 |
}
|
109 |
-
.
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
margin-
|
115 |
-
border:1px solid rgba(230,240,255,.7);
|
116 |
}
|
117 |
-
.example-
|
118 |
-
|
119 |
-
|
120 |
-
|
|
|
|
|
|
|
|
|
121 |
}
|
122 |
-
.example-item{
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
}
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
#
|
138 |
gr.HTML("""
|
139 |
-
|
140 |
-
<h1 style="font-size:2.8rem;margin-bottom
|
141 |
-
|
142 |
-
-webkit-background-clip:text;-webkit-text-fill-color:transparent;">
|
143 |
-
π¨ BadgeCraft
|
144 |
</h1>
|
145 |
-
<p style="font-size:1.2rem;margin
|
146 |
-
|
147 |
</p>
|
148 |
-
<div style="margin-top:10px;display:flex;justify-content:center;gap:12px;flex-wrap:wrap;">
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
<strong>π₯ Created by OpenFreeAI Team</strong>
|
156 |
-
</span>
|
157 |
</div>
|
158 |
-
|
159 |
""")
|
160 |
|
161 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
172 |
-
message
|
173 |
-
logo
|
174 |
-
style
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
190 |
|
191 |
-
#
|
192 |
examples = [
|
193 |
-
["Discord","Openfree
|
194 |
-
["X.com","Follow us","
|
195 |
-
["Collections","Explore","
|
196 |
-
|
197 |
-
["
|
198 |
-
["
|
199 |
-
["
|
200 |
-
["
|
201 |
-
["Threads","ν¨κ» μ¦κ²¨μ.","#000000","#FF00FF","threads","white","for-the-badge","https://www.threads.net/@openfree_ai"],
|
202 |
]
|
203 |
|
204 |
-
# μμ
|
205 |
html_items = '<div class="example-grid">'
|
206 |
for idx, ex in enumerate(examples):
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
216 |
html_items += f'''
|
217 |
<div class="example-item" onclick="applyExample({idx})">
|
218 |
-
|
219 |
-
|
220 |
</div>
|
221 |
'''
|
222 |
html_items += '</div>'
|
223 |
|
224 |
-
#
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
desc.set.call(el,val);
|
232 |
-
el.dispatchEvent(new Event("input",{bubbles:true}));
|
233 |
-
el.dispatchEvent(new Event("change",{bubbles:true}));
|
234 |
}
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
|
|
240 |
}
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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=
|
271 |
inputs=[label, message, color, label_color, logo, logo_color, style, link],
|
272 |
outputs=[out_code, out_preview]
|
273 |
)
|
274 |
-
|
275 |
-
|
276 |
-
|
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
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
</div>
|
321 |
''')
|
322 |
|
323 |
-
#
|
324 |
gr.HTML('''
|
325 |
<div class="footer">
|
326 |
-
|
327 |
-
|
328 |
-
|
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></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()
|