|
import urllib.parse |
|
import gradio as gr |
|
|
|
|
|
|
|
|
|
def generate_static_badge(label, message, color, style, label_color, logo, logo_color): |
|
base = "https://img.shields.io/static/v1" |
|
params = [] |
|
if label: |
|
params.append(f"label={urllib.parse.quote(label, safe='')}") |
|
if message: |
|
params.append(f"message={urllib.parse.quote(message, safe='')}") |
|
if color: |
|
params.append(f"color={urllib.parse.quote(color, safe='')}") |
|
if style: |
|
params.append(f"style={urllib.parse.quote(style, safe='')}") |
|
if label_color: |
|
params.append(f"labelColor={urllib.parse.quote(label_color, safe='')}") |
|
if logo: |
|
params.append(f"logo={urllib.parse.quote(logo, safe='')}") |
|
if logo_color: |
|
params.append(f"logoColor={urllib.parse.quote(logo_color, safe='')}") |
|
url = base + ("?" + "&".join(params) if params else "") |
|
html_code = f'<img src="{url}" alt="{label or message} badge">' |
|
return html_code, url |
|
|
|
def generate_dynamic_json_badge(json_url, json_path, label, prefix, suffix, color, style, label_color, logo, logo_color): |
|
base = "https://img.shields.io/badge/dynamic/json" |
|
params = [] |
|
if json_url: |
|
params.append(f"url={urllib.parse.quote(json_url, safe='')}") |
|
if json_path: |
|
params.append(f"query={urllib.parse.quote(json_path, safe='')}") |
|
if label: |
|
params.append(f"label={urllib.parse.quote(label, safe='')}") |
|
if prefix: |
|
params.append(f"prefix={urllib.parse.quote(prefix, safe='')}") |
|
if suffix: |
|
params.append(f"suffix={urllib.parse.quote(suffix, safe='')}") |
|
if color: |
|
params.append(f"color={urllib.parse.quote(color, safe='')}") |
|
if style: |
|
params.append(f"style={urllib.parse.quote(style, safe='')}") |
|
if label_color: |
|
params.append(f"labelColor={urllib.parse.quote(label_color, safe='')}") |
|
if logo: |
|
params.append(f"logo={urllib.parse.quote(logo, safe='')}") |
|
if logo_color: |
|
params.append(f"logoColor={urllib.parse.quote(logo_color, safe='')}") |
|
url = base + ("?" + "&".join(params) if params else "") |
|
html_code = f'<img src="{url}" alt="Dynamic JSON badge">' |
|
return html_code, url |
|
|
|
def generate_endpoint_badge(endpoint_url, label, color, style, label_color, logo, logo_color): |
|
base = "https://img.shields.io/endpoint" |
|
params = [] |
|
if endpoint_url: |
|
params.append(f"url={urllib.parse.quote(endpoint_url, safe='')}") |
|
if label: |
|
params.append(f"label={urllib.parse.quote(label, safe='')}") |
|
if color: |
|
params.append(f"color={urllib.parse.quote(color, safe='')}") |
|
if style: |
|
params.append(f"style={urllib.parse.quote(style, safe='')}") |
|
if label_color: |
|
params.append(f"labelColor={urllib.parse.quote(label_color, safe='')}") |
|
if logo: |
|
params.append(f"logo={urllib.parse.quote(logo, safe='')}") |
|
if logo_color: |
|
params.append(f"logoColor={urllib.parse.quote(logo_color, safe='')}") |
|
url = base + ("?" + "&".join(params) if params else "") |
|
html_code = f'<img src="{url}" alt="Endpoint badge">' |
|
return html_code, url |
|
|
|
|
|
|
|
|
|
with gr.Blocks(theme=gr.themes.Default()) as app: |
|
gr.Markdown(""" |
|
# Shields.io Badge Generator ๐ |
|
์ด ์ฑ์ [Shields.io](https://shields.io/)์์ ์ ๊ณตํ๋ ๋ฐฐ์ง๋ฅผ **GUI**๋ก ๊ฐํธํ๊ฒ ์์ฑํ๋๋ก ๋์์ค๋๋ค.<br> |
|
์๋ ํญ์์ ๋ฐฐ์ง ์ ํ์ ์ ํํ๊ณ ์ํ๋ ์ต์
์ ์
๋ ฅํด๋ณด์ธ์. ์๋์ผ๋ก HTML ์ฝ๋ ์ค๋ํซ๊ณผ ๋ฏธ๋ฆฌ๋ณด๊ธฐ ์ด๋ฏธ์ง๋ฅผ ํ์ธํ์ค ์ ์์ต๋๋ค. |
|
""") |
|
|
|
with gr.Tabs(): |
|
|
|
|
|
|
|
with gr.Tab("Static Badge"): |
|
gr.Markdown(""" |
|
**์ ์ (Static) ๋ฐฐ์ง**๋ฅผ ์์ฑํฉ๋๋ค. |
|
์: ์ข์ธก ํ
์คํธ(label), ์ฐ์ธก ํ
์คํธ(message), ์์(color) ๋ฑ์ ์
๋ ฅํ์ธ์. |
|
""") |
|
with gr.Row(): |
|
lbl = gr.Textbox(label="Label (์ข์ธก ํ
์คํธ)", placeholder="์: build") |
|
msg = gr.Textbox(label="Message (์ฐ์ธก ํ
์คํธ)", placeholder="์: passing") |
|
|
|
with gr.Row(): |
|
col = gr.Textbox(label="Color (์์)", value="blue", placeholder="์: brightgreen, #4c1 ๋ฑ") |
|
lbl_col = gr.Textbox(label="Label Color (๋ ์ด๋ธ ๋ฐฐ๊ฒฝ์)", placeholder="(์ ํ ์ฌํญ)") |
|
|
|
with gr.Row(): |
|
logo_in = gr.Textbox(label="Logo (์์ด์ฝ)", placeholder="์: github (์ ํ ์ฌํญ)") |
|
logo_col = gr.Textbox(label="Logo Color (์์ด์ฝ ์์)", placeholder="(์ ํ ์ฌํญ)") |
|
|
|
style_in = gr.Dropdown( |
|
label="Style (์คํ์ผ)", |
|
choices=["flat", "flat-square", "plastic", "for-the-badge", "social"], |
|
value="flat" |
|
) |
|
|
|
|
|
out_code = gr.Code(label="HTML Snippet", language="html") |
|
out_img = gr.Image(label="Badge Preview", type="auto") |
|
|
|
|
|
inputs = [lbl, msg, col, style_in, lbl_col, logo_in, logo_col] |
|
for inp in inputs: |
|
inp.change( |
|
fn=generate_static_badge, |
|
inputs=inputs, |
|
outputs=[out_code, out_img] |
|
) |
|
|
|
|
|
|
|
|
|
with gr.Tab("Dynamic JSON Badge"): |
|
gr.Markdown(""" |
|
**๋์ (JSON) ๋ฐฐ์ง**๋ฅผ ์์ฑํฉ๋๋ค. |
|
URL๋ก๋ถํฐ JSON ๋ฐ์ดํฐ๋ฅผ ์ฝ์ด์ ํน์ ํ๋๋ฅผ ์ถ์ถํ์ฌ ํ์ํฉ๋๋ค. |
|
""") |
|
with gr.Row(): |
|
json_url = gr.Textbox(label="JSON URL", placeholder="์: https://example.com/data.json") |
|
json_path = gr.Textbox(label="JSONPath Query", placeholder="์: $.version") |
|
|
|
with gr.Row(): |
|
label_dyn = gr.Textbox(label="Label (์ข์ธก ํ
์คํธ)", placeholder="(์ ํ ์ฌํญ)") |
|
prefix_dyn = gr.Textbox(label="Prefix (์ ๋์ฌ)", placeholder="๊ฐ ์์ ๋ถ์ผ ๋ฌธ์์ด (์ ํ)") |
|
suffix_dyn = gr.Textbox(label="Suffix (์ ๋ฏธ์ฌ)", placeholder="๊ฐ ๋ค์ ๋ถ์ผ ๋ฌธ์์ด (์ ํ)") |
|
|
|
with gr.Row(): |
|
color_dyn = gr.Textbox(label="Color (์์)", value="blue", placeholder="์: blue, #4183c4 ๋ฑ") |
|
lbl_color_dyn = gr.Textbox(label="Label Color (๋ ์ด๋ธ ๋ฐฐ๊ฒฝ์)", placeholder="(์ ํ ์ฌํญ)") |
|
|
|
with gr.Row(): |
|
logo_dyn = gr.Textbox(label="Logo (์์ด์ฝ)", placeholder="์: google (์ ํ ์ฌํญ)") |
|
logo_color_dyn = gr.Textbox(label="Logo Color (์์ด์ฝ ์์)", placeholder="(์ ํ ์ฌํญ)") |
|
|
|
style_dyn = gr.Dropdown( |
|
label="Style (์คํ์ผ)", |
|
choices=["flat", "flat-square", "plastic", "for-the-badge", "social"], |
|
value="flat" |
|
) |
|
|
|
out_code2 = gr.Code(label="HTML Snippet", language="html") |
|
out_img2 = gr.Image(label="Badge Preview", type="auto") |
|
|
|
inputs_dyn = [ |
|
json_url, json_path, label_dyn, prefix_dyn, suffix_dyn, |
|
color_dyn, style_dyn, lbl_color_dyn, logo_dyn, logo_color_dyn |
|
] |
|
for inp in inputs_dyn: |
|
inp.change( |
|
fn=generate_dynamic_json_badge, |
|
inputs=inputs_dyn, |
|
outputs=[out_code2, out_img2] |
|
) |
|
|
|
|
|
|
|
|
|
with gr.Tab("Endpoint Badge"): |
|
gr.Markdown(""" |
|
**Endpoint ๋ฐฐ์ง**๋ฅผ ์์ฑํฉ๋๋ค. |
|
์๋ํฌ์ธํธ(Endpoint)์์ ๋ฏธ๋ฆฌ ์ ์๋ JSON ๊ตฌ์กฐ(`schemaVersion`, `label`, `message`, `color` ๋ฑ)๋ฅผ ๋ฐํํ๊ณ , |
|
Shields.io๊ฐ ์ด๋ฅผ ์ฝ์ด์ ๋ฐฐ์ง๋ฅผ ๋ ๋๋งํฉ๋๋ค. |
|
""") |
|
with gr.Row(): |
|
endpoint = gr.Textbox(label="Endpoint URL", placeholder="๋ฐฐ์ง JSON์ ์ ๊ณตํ๋ ์๋ํฌ์ธํธ URL") |
|
label_ep = gr.Textbox(label="Override Label", placeholder="์๋ํฌ์ธํธ JSON์ label ๋์ (์ ํ)") |
|
|
|
with gr.Row(): |
|
color_ep = gr.Textbox(label="Override Color", placeholder="์๋ํฌ์ธํธ JSON์ color ๋์ (์ ํ)") |
|
lbl_color_ep = gr.Textbox(label="Label Color", placeholder="(์ ํ ์ฌํญ)") |
|
|
|
with gr.Row(): |
|
logo_ep = gr.Textbox(label="Logo (์์ด์ฝ)", placeholder="์: custom (์ ํ ์ฌํญ)") |
|
logo_color_ep = gr.Textbox(label="Logo Color", placeholder="(์ ํ ์ฌํญ)") |
|
|
|
style_ep = gr.Dropdown( |
|
label="Style (์คํ์ผ)", |
|
choices=["flat", "flat-square", "plastic", "for-the-badge", "social"], |
|
value="flat" |
|
) |
|
|
|
out_code3 = gr.Code(label="HTML Snippet", language="html") |
|
out_img3 = gr.Image(label="Badge Preview", type="auto") |
|
|
|
inputs_ep = [ |
|
endpoint, label_ep, color_ep, style_ep, |
|
lbl_color_ep, logo_ep, logo_color_ep |
|
] |
|
for inp in inputs_ep: |
|
inp.change( |
|
fn=generate_endpoint_badge, |
|
inputs=inputs_ep, |
|
outputs=[out_code3, out_img3] |
|
) |
|
|
|
|
|
|
|
|
|
app.launch() |
|
|