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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import urllib.parse
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
# ----------------------------------------------------
|
| 5 |
+
# 1. ๋ฐฐ์ง URL ์์ฑ ํจ์ ์ ์
|
| 6 |
+
# ----------------------------------------------------
|
| 7 |
+
def generate_static_badge(label, message, color, style, label_color, logo, logo_color):
|
| 8 |
+
base = "https://img.shields.io/static/v1"
|
| 9 |
+
params = []
|
| 10 |
+
if label: # 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 style:
|
| 17 |
+
params.append(f"style={urllib.parse.quote(style, safe='')}")
|
| 18 |
+
if label_color:
|
| 19 |
+
params.append(f"labelColor={urllib.parse.quote(label_color, safe='')}")
|
| 20 |
+
if logo:
|
| 21 |
+
params.append(f"logo={urllib.parse.quote(logo, safe='')}")
|
| 22 |
+
if logo_color:
|
| 23 |
+
params.append(f"logoColor={urllib.parse.quote(logo_color, safe='')}")
|
| 24 |
+
url = base + ("?" + "&".join(params) if params else "")
|
| 25 |
+
html_code = f'<img src="{url}" alt="{label or message} badge">'
|
| 26 |
+
return html_code, url # (HTML ์ฝ๋ ์ค๋ํซ, ์ด๋ฏธ์ง URL)์ ๋ฐํ
|
| 27 |
+
|
| 28 |
+
def generate_dynamic_json_badge(json_url, json_path, label, prefix, suffix, color, style, label_color, logo, logo_color):
|
| 29 |
+
base = "https://img.shields.io/badge/dynamic/json"
|
| 30 |
+
params = []
|
| 31 |
+
if json_url:
|
| 32 |
+
params.append(f"url={urllib.parse.quote(json_url, safe='')}")
|
| 33 |
+
if json_path:
|
| 34 |
+
params.append(f"query={urllib.parse.quote(json_path, safe='')}")
|
| 35 |
+
if label:
|
| 36 |
+
params.append(f"label={urllib.parse.quote(label, safe='')}")
|
| 37 |
+
if prefix:
|
| 38 |
+
params.append(f"prefix={urllib.parse.quote(prefix, safe='')}")
|
| 39 |
+
if suffix:
|
| 40 |
+
params.append(f"suffix={urllib.parse.quote(suffix, safe='')}")
|
| 41 |
+
if color:
|
| 42 |
+
params.append(f"color={urllib.parse.quote(color, safe='')}")
|
| 43 |
+
if style:
|
| 44 |
+
params.append(f"style={urllib.parse.quote(style, safe='')}")
|
| 45 |
+
if label_color:
|
| 46 |
+
params.append(f"labelColor={urllib.parse.quote(label_color, safe='')}")
|
| 47 |
+
if logo:
|
| 48 |
+
params.append(f"logo={urllib.parse.quote(logo, safe='')}")
|
| 49 |
+
if logo_color:
|
| 50 |
+
params.append(f"logoColor={urllib.parse.quote(logo_color, safe='')}")
|
| 51 |
+
url = base + ("?" + "&".join(params) if params else "")
|
| 52 |
+
html_code = f'<img src="{url}" alt="Dynamic JSON badge">'
|
| 53 |
+
return html_code, url
|
| 54 |
+
|
| 55 |
+
def generate_endpoint_badge(endpoint_url, label, color, style, label_color, logo, logo_color):
|
| 56 |
+
base = "https://img.shields.io/endpoint"
|
| 57 |
+
params = []
|
| 58 |
+
if endpoint_url:
|
| 59 |
+
params.append(f"url={urllib.parse.quote(endpoint_url, safe='')}")
|
| 60 |
+
if label:
|
| 61 |
+
params.append(f"label={urllib.parse.quote(label, safe='')}")
|
| 62 |
+
if color:
|
| 63 |
+
params.append(f"color={urllib.parse.quote(color, safe='')}")
|
| 64 |
+
if style:
|
| 65 |
+
params.append(f"style={urllib.parse.quote(style, safe='')}")
|
| 66 |
+
if label_color:
|
| 67 |
+
params.append(f"labelColor={urllib.parse.quote(label_color, safe='')}")
|
| 68 |
+
if logo:
|
| 69 |
+
params.append(f"logo={urllib.parse.quote(logo, safe='')}")
|
| 70 |
+
if logo_color:
|
| 71 |
+
params.append(f"logoColor={urllib.parse.quote(logo_color, safe='')}")
|
| 72 |
+
url = base + ("?" + "&".join(params) if params else "")
|
| 73 |
+
html_code = f'<img src="{url}" alt="Endpoint badge">'
|
| 74 |
+
return html_code, url
|
| 75 |
+
|
| 76 |
+
# ----------------------------------------------------
|
| 77 |
+
# 2. Gradio UI ๊ตฌ์ฑ
|
| 78 |
+
# ----------------------------------------------------
|
| 79 |
+
with gr.Blocks(theme=gr.themes.Default()) as app:
|
| 80 |
+
gr.Markdown("""
|
| 81 |
+
# Shields.io Badge Generator ๐
|
| 82 |
+
์ด ์ฑ์ [Shields.io](https://shields.io/)์์ ์ ๊ณตํ๋ ๋ฐฐ์ง๋ฅผ **GUI**๋ก ๊ฐํธํ๊ฒ ์์ฑํ๋๋ก ๋์์ค๋๋ค.<br>
|
| 83 |
+
์๋ ํญ์์ ๋ฐฐ์ง ์ ํ์ ์ ํํ๊ณ ์ํ๋ ์ต์
์ ์
๋ ฅํด๋ณด์ธ์. ์๋์ผ๋ก HTML ์ฝ๋ ์ค๋ํซ๊ณผ ๋ฏธ๋ฆฌ๋ณด๊ธฐ ์ด๋ฏธ์ง๋ฅผ ํ์ธํ์ค ์ ์์ต๋๋ค.
|
| 84 |
+
""")
|
| 85 |
+
|
| 86 |
+
with gr.Tabs():
|
| 87 |
+
# ------------------------------------------------
|
| 88 |
+
# --- Tab 1: Static Badge ---
|
| 89 |
+
# ------------------------------------------------
|
| 90 |
+
with gr.Tab("Static Badge"):
|
| 91 |
+
gr.Markdown("""
|
| 92 |
+
**์ ์ (Static) ๋ฐฐ์ง**๋ฅผ ์์ฑํฉ๋๋ค.
|
| 93 |
+
์: ์ข์ธก ํ
์คํธ(label), ์ฐ์ธก ํ
์คํธ(message), ์์(color) ๋ฑ์ ์
๋ ฅํ์ธ์.
|
| 94 |
+
""")
|
| 95 |
+
with gr.Row():
|
| 96 |
+
lbl = gr.Textbox(label="Label (์ข์ธก ํ
์คํธ)", placeholder="์: build")
|
| 97 |
+
msg = gr.Textbox(label="Message (์ฐ์ธก ํ
์คํธ)", placeholder="์: passing")
|
| 98 |
+
|
| 99 |
+
with gr.Row():
|
| 100 |
+
col = gr.Textbox(label="Color (์์)", value="blue", placeholder="์: brightgreen, #4c1 ๋ฑ")
|
| 101 |
+
lbl_col = gr.Textbox(label="Label Color (๋ ์ด๋ธ ๋ฐฐ๊ฒฝ์)", placeholder="(์ ํ ์ฌํญ)")
|
| 102 |
+
|
| 103 |
+
with gr.Row():
|
| 104 |
+
logo_in = gr.Textbox(label="Logo (์์ด์ฝ)", placeholder="์: github (์ ํ ์ฌํญ)")
|
| 105 |
+
logo_col = gr.Textbox(label="Logo Color (์์ด์ฝ ์์)", placeholder="(์ ํ ์ฌํญ)")
|
| 106 |
+
|
| 107 |
+
style_in = gr.Dropdown(
|
| 108 |
+
label="Style (์คํ์ผ)",
|
| 109 |
+
choices=["flat", "flat-square", "plastic", "for-the-badge", "social"],
|
| 110 |
+
value="flat"
|
| 111 |
+
)
|
| 112 |
+
|
| 113 |
+
# ์ถ๋ ฅ: ์ฝ๋ ์ค๋ํซ & ์ด๋ฏธ์ง ๋ฏธ๋ฆฌ๋ณด๊ธฐ
|
| 114 |
+
out_code = gr.Code(label="HTML Snippet", language="html")
|
| 115 |
+
out_img = gr.Image(label="Badge Preview", type="auto")
|
| 116 |
+
|
| 117 |
+
# ์
๋ ฅ ๋ณํ -> ์ถ๋ ฅ ๊ฐฑ์
|
| 118 |
+
inputs = [lbl, msg, col, style_in, lbl_col, logo_in, logo_col]
|
| 119 |
+
for inp in inputs:
|
| 120 |
+
inp.change(
|
| 121 |
+
fn=generate_static_badge,
|
| 122 |
+
inputs=inputs,
|
| 123 |
+
outputs=[out_code, out_img]
|
| 124 |
+
)
|
| 125 |
+
|
| 126 |
+
# ------------------------------------------------
|
| 127 |
+
# --- Tab 2: Dynamic JSON Badge ---
|
| 128 |
+
# ------------------------------------------------
|
| 129 |
+
with gr.Tab("Dynamic JSON Badge"):
|
| 130 |
+
gr.Markdown("""
|
| 131 |
+
**๋์ (JSON) ๋ฐฐ์ง**๋ฅผ ์์ฑํฉ๋๋ค.
|
| 132 |
+
URL๋ก๋ถํฐ JSON ๋ฐ์ดํฐ๋ฅผ ์ฝ์ด์ ํน์ ํ๋๋ฅผ ์ถ์ถํ์ฌ ํ์ํฉ๋๋ค.
|
| 133 |
+
""")
|
| 134 |
+
with gr.Row():
|
| 135 |
+
json_url = gr.Textbox(label="JSON URL", placeholder="์: https://example.com/data.json")
|
| 136 |
+
json_path = gr.Textbox(label="JSONPath Query", placeholder="์: $.version")
|
| 137 |
+
|
| 138 |
+
with gr.Row():
|
| 139 |
+
label_dyn = gr.Textbox(label="Label (์ข์ธก ํ
์คํธ)", placeholder="(์ ํ ์ฌํญ)")
|
| 140 |
+
prefix_dyn = gr.Textbox(label="Prefix (์ ๋์ฌ)", placeholder="๊ฐ ์์ ๋ถ์ผ ๋ฌธ์์ด (์ ํ)")
|
| 141 |
+
suffix_dyn = gr.Textbox(label="Suffix (์ ๋ฏธ์ฌ)", placeholder="๊ฐ ๋ค์ ๋ถ์ผ ๋ฌธ์์ด (์ ํ)")
|
| 142 |
+
|
| 143 |
+
with gr.Row():
|
| 144 |
+
color_dyn = gr.Textbox(label="Color (์์)", value="blue", placeholder="์: blue, #4183c4 ๋ฑ")
|
| 145 |
+
lbl_color_dyn = gr.Textbox(label="Label Color (๋ ์ด๋ธ ๋ฐฐ๊ฒฝ์)", placeholder="(์ ํ ์ฌํญ)")
|
| 146 |
+
|
| 147 |
+
with gr.Row():
|
| 148 |
+
logo_dyn = gr.Textbox(label="Logo (์์ด์ฝ)", placeholder="์: google (์ ํ ์ฌํญ)")
|
| 149 |
+
logo_color_dyn = gr.Textbox(label="Logo Color (์์ด์ฝ ์์)", placeholder="(์ ํ ์ฌํญ)")
|
| 150 |
+
|
| 151 |
+
style_dyn = gr.Dropdown(
|
| 152 |
+
label="Style (์คํ์ผ)",
|
| 153 |
+
choices=["flat", "flat-square", "plastic", "for-the-badge", "social"],
|
| 154 |
+
value="flat"
|
| 155 |
+
)
|
| 156 |
+
|
| 157 |
+
out_code2 = gr.Code(label="HTML Snippet", language="html")
|
| 158 |
+
out_img2 = gr.Image(label="Badge Preview", type="auto")
|
| 159 |
+
|
| 160 |
+
inputs_dyn = [
|
| 161 |
+
json_url, json_path, label_dyn, prefix_dyn, suffix_dyn,
|
| 162 |
+
color_dyn, style_dyn, lbl_color_dyn, logo_dyn, logo_color_dyn
|
| 163 |
+
]
|
| 164 |
+
for inp in inputs_dyn:
|
| 165 |
+
inp.change(
|
| 166 |
+
fn=generate_dynamic_json_badge,
|
| 167 |
+
inputs=inputs_dyn,
|
| 168 |
+
outputs=[out_code2, out_img2]
|
| 169 |
+
)
|
| 170 |
+
|
| 171 |
+
# ------------------------------------------------
|
| 172 |
+
# --- Tab 3: Endpoint Badge ---
|
| 173 |
+
# ------------------------------------------------
|
| 174 |
+
with gr.Tab("Endpoint Badge"):
|
| 175 |
+
gr.Markdown("""
|
| 176 |
+
**Endpoint ๋ฐฐ์ง**๋ฅผ ์์ฑํฉ๋๋ค.
|
| 177 |
+
์๋ํฌ์ธํธ(Endpoint)์์ ๋ฏธ๋ฆฌ ์ ์๋ JSON ๊ตฌ์กฐ(`schemaVersion`, `label`, `message`, `color` ๋ฑ)๋ฅผ ๋ฐํํ๊ณ ,
|
| 178 |
+
Shields.io๊ฐ ์ด๋ฅผ ์ฝ์ด์ ๋ฐฐ์ง๋ฅผ ๋ ๋๋งํฉ๋๋ค.
|
| 179 |
+
""")
|
| 180 |
+
with gr.Row():
|
| 181 |
+
endpoint = gr.Textbox(label="Endpoint URL", placeholder="๋ฐฐ์ง JSON์ ์ ๊ณตํ๋ ์๋ํฌ์ธํธ URL")
|
| 182 |
+
label_ep = gr.Textbox(label="Override Label", placeholder="์๋ํฌ์ธํธ JSON์ label ๋์ (์ ํ)")
|
| 183 |
+
|
| 184 |
+
with gr.Row():
|
| 185 |
+
color_ep = gr.Textbox(label="Override Color", placeholder="์๋ํฌ์ธํธ JSON์ color ๋์ (์ ํ)")
|
| 186 |
+
lbl_color_ep = gr.Textbox(label="Label Color", placeholder="(์ ํ ์ฌํญ)")
|
| 187 |
+
|
| 188 |
+
with gr.Row():
|
| 189 |
+
logo_ep = gr.Textbox(label="Logo (์์ด์ฝ)", placeholder="์: custom (์ ํ ์ฌํญ)")
|
| 190 |
+
logo_color_ep = gr.Textbox(label="Logo Color", placeholder="(์ ํ ์ฌํญ)")
|
| 191 |
+
|
| 192 |
+
style_ep = gr.Dropdown(
|
| 193 |
+
label="Style (์คํ์ผ)",
|
| 194 |
+
choices=["flat", "flat-square", "plastic", "for-the-badge", "social"],
|
| 195 |
+
value="flat"
|
| 196 |
+
)
|
| 197 |
+
|
| 198 |
+
out_code3 = gr.Code(label="HTML Snippet", language="html")
|
| 199 |
+
out_img3 = gr.Image(label="Badge Preview", type="auto")
|
| 200 |
+
|
| 201 |
+
inputs_ep = [
|
| 202 |
+
endpoint, label_ep, color_ep, style_ep,
|
| 203 |
+
lbl_color_ep, logo_ep, logo_color_ep
|
| 204 |
+
]
|
| 205 |
+
for inp in inputs_ep:
|
| 206 |
+
inp.change(
|
| 207 |
+
fn=generate_endpoint_badge,
|
| 208 |
+
inputs=inputs_ep,
|
| 209 |
+
outputs=[out_code3, out_img3]
|
| 210 |
+
)
|
| 211 |
+
|
| 212 |
+
# ์ ์ฒด Blocks ์ข
๋ฃ
|
| 213 |
+
|
| 214 |
+
# ์ค์ ์คํ ์ ์๋ ์ฃผ์์ ํด์ ํ์ฌ ์ฌ์ฉํ์ธ์.
|
| 215 |
+
app.launch()
|