fantos commited on
Commit
ef7934a
ยท
verified ยท
1 Parent(s): 255baa5

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +215 -0
app.py ADDED
@@ -0,0 +1,215 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()