Update app.py
Browse files
app.py
CHANGED
@@ -12,13 +12,14 @@ def generate_static_badge(label, message, color, label_color, logo, logo_color,
|
|
12 |
if message:
|
13 |
params.append(f"message={urllib.parse.quote(message, safe='')}")
|
14 |
if color:
|
15 |
-
|
|
|
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 |
|
@@ -175,9 +176,9 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
175 |
value="for-the-badge",
|
176 |
elem_id="style-input"
|
177 |
)
|
178 |
-
color = gr.ColorPicker(label="Background Color", value="#5865F2", elem_id="color-input")
|
179 |
-
label_color = gr.ColorPicker(label="Label Background Color", value="#99AAFF", elem_id="label-color-input")
|
180 |
-
logo_color = gr.ColorPicker(label="Logo Color", value="#ffffff", elem_id="logo-color-input")
|
181 |
link = gr.Textbox(label="Link (URL)", value="https://discord.gg/openfreeai", elem_id="link-input", lines=1)
|
182 |
with gr.Column():
|
183 |
with gr.Group(elem_classes="badge-section"):
|
@@ -208,8 +209,8 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
208 |
"https://img.shields.io/static/v1?" + "&".join([
|
209 |
f"label={urllib.parse.quote(ex[0], safe='')}",
|
210 |
f"message={urllib.parse.quote(ex[1], safe='')}",
|
211 |
-
f"color={urllib.parse.quote(ex[2], safe='')}",
|
212 |
-
f"labelColor={urllib.parse.quote(ex[3], safe='')}",
|
213 |
f"logo={urllib.parse.quote(ex[4], safe='')}",
|
214 |
f"logoColor={urllib.parse.quote(ex[5], safe='')}",
|
215 |
f"style={urllib.parse.quote(ex[6], safe='')}"
|
@@ -254,17 +255,30 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
254 |
const container = document.getElementById(elemId);
|
255 |
if (!container) return;
|
256 |
|
257 |
-
// Gradio ColorPicker
|
258 |
-
|
259 |
-
if (
|
260 |
-
|
261 |
-
|
|
|
|
|
|
|
|
|
|
|
262 |
|
263 |
-
//
|
264 |
-
const colorArea = container.querySelector("[data-testid='color-picker']");
|
265 |
if (colorArea) {
|
266 |
colorArea.style.background = colorValue;
|
267 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
268 |
}
|
269 |
|
270 |
const examples = REPLACE_EXAMPLES; // placeholder
|
@@ -276,20 +290,38 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
276 |
reactSet(document.querySelector("#label-input input,#label-input textarea"), ex[0]);
|
277 |
// Message
|
278 |
reactSet(document.querySelector("#message-input input,#message-input textarea"), ex[1]);
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
283 |
// Logo
|
284 |
reactSet(document.querySelector("#logo-input input,#logo-input textarea"), ex[4]);
|
285 |
-
|
286 |
-
setColor("logo-color-input", convertToHexIfNeeded(ex[5]));
|
287 |
// Style (Dropdown)
|
288 |
const styleSelect = document.querySelector("#style-input select");
|
289 |
if (styleSelect) {
|
290 |
styleSelect.value = ex[6];
|
291 |
styleSelect.dispatchEvent(new Event("change", { bubbles: true }));
|
292 |
}
|
|
|
293 |
// Link
|
294 |
reactSet(document.querySelector("#link-input input,#link-input textarea"), ex[7]);
|
295 |
}
|
@@ -304,18 +336,24 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
304 |
# ---------------------------
|
305 |
# 4) ์ค์๊ฐ ์
๋ฐ์ดํธ
|
306 |
# ---------------------------
|
|
|
|
|
|
|
|
|
307 |
# - ์ด๊ธฐ ๋ก๋
|
308 |
demo.load(
|
309 |
-
fn=
|
310 |
inputs=[label, message, color, label_color, logo, logo_color, style, link],
|
311 |
outputs=[out_code, out_preview]
|
312 |
)
|
313 |
-
|
|
|
314 |
for inp in [label, message, color, label_color, logo, logo_color, style, link]:
|
315 |
inp.change(
|
316 |
-
fn=
|
317 |
inputs=[label, message, color, label_color, logo, logo_color, style, link],
|
318 |
-
outputs=[out_code, out_preview]
|
|
|
319 |
)
|
320 |
|
321 |
# ---------------------------
|
@@ -365,4 +403,4 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
365 |
''')
|
366 |
|
367 |
if __name__ == "__main__":
|
368 |
-
demo.launch()
|
|
|
12 |
if message:
|
13 |
params.append(f"message={urllib.parse.quote(message, safe='')}")
|
14 |
if color:
|
15 |
+
# ์์์์ # ๊ธฐํธ ์ ๊ฑฐ (URL ์ธ์ฝ๋ฉ ๋ฌธ์ ๋ฐฉ์ง)
|
16 |
+
params.append(f"color={urllib.parse.quote(color.lstrip('#'), safe='')}")
|
17 |
if label_color:
|
18 |
+
params.append(f"labelColor={urllib.parse.quote(label_color.lstrip('#'), safe='')}")
|
19 |
if logo:
|
20 |
params.append(f"logo={urllib.parse.quote(logo, safe='')}")
|
21 |
if logo_color:
|
22 |
+
params.append(f"logoColor={urllib.parse.quote(logo_color.lstrip('#'), safe='')}")
|
23 |
if style:
|
24 |
params.append(f"style={urllib.parse.quote(style, safe='')}")
|
25 |
|
|
|
176 |
value="for-the-badge",
|
177 |
elem_id="style-input"
|
178 |
)
|
179 |
+
color = gr.ColorPicker(label="Background Color", value="#5865F2", elem_id="color-input", interactive=True)
|
180 |
+
label_color = gr.ColorPicker(label="Label Background Color", value="#99AAFF", elem_id="label-color-input", interactive=True)
|
181 |
+
logo_color = gr.ColorPicker(label="Logo Color", value="#ffffff", elem_id="logo-color-input", interactive=True)
|
182 |
link = gr.Textbox(label="Link (URL)", value="https://discord.gg/openfreeai", elem_id="link-input", lines=1)
|
183 |
with gr.Column():
|
184 |
with gr.Group(elem_classes="badge-section"):
|
|
|
209 |
"https://img.shields.io/static/v1?" + "&".join([
|
210 |
f"label={urllib.parse.quote(ex[0], safe='')}",
|
211 |
f"message={urllib.parse.quote(ex[1], safe='')}",
|
212 |
+
f"color={urllib.parse.quote(ex[2].lstrip('#'), safe='')}",
|
213 |
+
f"labelColor={urllib.parse.quote(ex[3].lstrip('#'), safe='')}",
|
214 |
f"logo={urllib.parse.quote(ex[4], safe='')}",
|
215 |
f"logoColor={urllib.parse.quote(ex[5], safe='')}",
|
216 |
f"style={urllib.parse.quote(ex[6], safe='')}"
|
|
|
255 |
const container = document.getElementById(elemId);
|
256 |
if (!container) return;
|
257 |
|
258 |
+
// Gradio ColorPicker ์ปดํฌ๋ํธ ๋ด๋ถ ๊ตฌ์กฐ ์ ๊ทผ
|
259 |
+
const colorInputs = container.querySelectorAll("input");
|
260 |
+
if (colorInputs.length === 0) return;
|
261 |
+
|
262 |
+
// ์ปฌ๋ฌํผ์ปค ์์ ๋ฐ ํ
์คํธ ์
๋ ฅ ์์ ๋ชจ๋์ ์ ์ฉ
|
263 |
+
for (const input of colorInputs) {
|
264 |
+
if (input.type === 'color' || input.type === 'text') {
|
265 |
+
reactSet(input, colorValue);
|
266 |
+
}
|
267 |
+
}
|
268 |
|
269 |
+
// ์์ ํ์ ์์ญ ์
๋ฐ์ดํธ (Gradio ๋ฒ์ ์ ๋ฐ๋ผ ์ ํ์ ๋ฌ๋ผ์ง ์ ์์)
|
270 |
+
const colorArea = container.querySelector("[data-testid='color-picker'], .color-circle, .color-preview");
|
271 |
if (colorArea) {
|
272 |
colorArea.style.background = colorValue;
|
273 |
}
|
274 |
+
|
275 |
+
// ์ถ๊ฐ: ๋ณ๊ฒฝ ์ฌํญ ์ค์๊ฐ ๋ฐ์์ ์ํ ์ฒ๋ฆฌ
|
276 |
+
setTimeout(() => {
|
277 |
+
const anyInput = colorInputs[0];
|
278 |
+
if (anyInput) {
|
279 |
+
anyInput.dispatchEvent(new Event('change', { bubbles: true }));
|
280 |
+
}
|
281 |
+
}, 50);
|
282 |
}
|
283 |
|
284 |
const examples = REPLACE_EXAMPLES; // placeholder
|
|
|
290 |
reactSet(document.querySelector("#label-input input,#label-input textarea"), ex[0]);
|
291 |
// Message
|
292 |
reactSet(document.querySelector("#message-input input,#message-input textarea"), ex[1]);
|
293 |
+
|
294 |
+
// ์์ ์ค์ - ์ ์ฉ ์์์ ์ง์ฐ ์ถ๊ฐ
|
295 |
+
setTimeout(() => {
|
296 |
+
// Background Color
|
297 |
+
setColor("color-input", convertToHexIfNeeded(ex[2]));
|
298 |
+
|
299 |
+
setTimeout(() => {
|
300 |
+
// Label Background
|
301 |
+
setColor("label-color-input", convertToHexIfNeeded(ex[3]));
|
302 |
+
|
303 |
+
setTimeout(() => {
|
304 |
+
// Logo Color
|
305 |
+
setColor("logo-color-input", convertToHexIfNeeded(ex[5]));
|
306 |
+
|
307 |
+
// ๋ชจ๋ ์์ ์ค์ ํ ๊ฐ์ ์
๋ฐ์ดํธ ํธ๋ฆฌ๊ฑฐ
|
308 |
+
document.querySelector("#label-input input").dispatchEvent(
|
309 |
+
new Event('change', { bubbles: true })
|
310 |
+
);
|
311 |
+
}, 50);
|
312 |
+
}, 50);
|
313 |
+
}, 50);
|
314 |
+
|
315 |
// Logo
|
316 |
reactSet(document.querySelector("#logo-input input,#logo-input textarea"), ex[4]);
|
317 |
+
|
|
|
318 |
// Style (Dropdown)
|
319 |
const styleSelect = document.querySelector("#style-input select");
|
320 |
if (styleSelect) {
|
321 |
styleSelect.value = ex[6];
|
322 |
styleSelect.dispatchEvent(new Event("change", { bubbles: true }));
|
323 |
}
|
324 |
+
|
325 |
// Link
|
326 |
reactSet(document.querySelector("#link-input input,#link-input textarea"), ex[7]);
|
327 |
}
|
|
|
336 |
# ---------------------------
|
337 |
# 4) ์ค์๊ฐ ์
๋ฐ์ดํธ
|
338 |
# ---------------------------
|
339 |
+
# ์ค์๊ฐ ์
๋ฐ์ดํธ ๋น๋ ์ฆ๊ฐ ๋ฐ ๋ณ๋ ํจ์ ์ถ๊ฐ
|
340 |
+
def update_badge(*args):
|
341 |
+
return generate_static_badge(*args)
|
342 |
+
|
343 |
# - ์ด๊ธฐ ๋ก๋
|
344 |
demo.load(
|
345 |
+
fn=update_badge,
|
346 |
inputs=[label, message, color, label_color, logo, logo_color, style, link],
|
347 |
outputs=[out_code, out_preview]
|
348 |
)
|
349 |
+
|
350 |
+
# - ๋ณ๊ฒฝ ์ด๋ฒคํธ - ๊ฐ ์
๋ ฅ์ ๋ํด ๋
๋ฆฝ์ ์ผ๋ก ์ฒ๋ฆฌ
|
351 |
for inp in [label, message, color, label_color, logo, logo_color, style, link]:
|
352 |
inp.change(
|
353 |
+
fn=update_badge,
|
354 |
inputs=[label, message, color, label_color, logo, logo_color, style, link],
|
355 |
+
outputs=[out_code, out_preview],
|
356 |
+
queue=False # ๋น ๋ฅธ ์๋ต์ ์ํด ํ ์ฌ์ฉ ์ ํจ
|
357 |
)
|
358 |
|
359 |
# ---------------------------
|
|
|
403 |
''')
|
404 |
|
405 |
if __name__ == "__main__":
|
406 |
+
demo.launch()
|