|
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() |
|
|