Update app-backup.py
Browse files- app-backup.py +62 -31
app-backup.py
CHANGED
@@ -1,7 +1,10 @@
|
|
1 |
import urllib.parse
|
2 |
import gradio as gr
|
3 |
|
4 |
-
|
|
|
|
|
|
|
5 |
base = "https://img.shields.io/static/v1"
|
6 |
params = []
|
7 |
if label:
|
@@ -10,51 +13,79 @@ def generate_static_badge(label, message, color, style, label_color, logo, logo_
|
|
10 |
params.append(f"message={urllib.parse.quote(message, safe='')}")
|
11 |
if color:
|
12 |
params.append(f"color={urllib.parse.quote(color, safe='')}")
|
13 |
-
if style:
|
14 |
-
params.append(f"style={urllib.parse.quote(style, safe='')}")
|
15 |
if label_color:
|
16 |
params.append(f"labelColor={urllib.parse.quote(label_color, safe='')}")
|
17 |
if logo:
|
18 |
params.append(f"logo={urllib.parse.quote(logo, safe='')}")
|
19 |
if logo_color:
|
20 |
params.append(f"logoColor={urllib.parse.quote(logo_color, safe='')}")
|
|
|
|
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
|
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
<img src="{url}" alt="Badge Preview">
|
30 |
</div>
|
31 |
"""
|
32 |
-
return html_code,
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
-
|
36 |
-
gr.
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
msg = gr.Textbox(label="Message")
|
41 |
with gr.Row():
|
42 |
-
|
43 |
-
|
|
|
44 |
with gr.Row():
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
value="flat"
|
51 |
-
)
|
52 |
|
53 |
-
|
54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
-
|
|
|
57 |
for inp in inputs:
|
58 |
-
inp.change(fn=generate_static_badge, inputs=inputs, outputs=[out_code,
|
59 |
|
60 |
-
|
|
|
|
|
|
1 |
import urllib.parse
|
2 |
import gradio as gr
|
3 |
|
4 |
+
# ---------------------------
|
5 |
+
# ๋ฐฐ์ง URL ์์ฑ ํจ์ ์ ์
|
6 |
+
# ---------------------------
|
7 |
+
def generate_static_badge(label, message, color, label_color, logo, logo_color, style, link):
|
8 |
base = "https://img.shields.io/static/v1"
|
9 |
params = []
|
10 |
if label:
|
|
|
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 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 |
|
25 |
+
badge_url = base + ("?" + "&".join(params) if params else "")
|
26 |
+
if link:
|
27 |
+
html_code = f'<a href="{link}" target="_blank"><img src="{badge_url}" alt="badge"></a>'
|
28 |
+
else:
|
29 |
+
html_code = f'<img src="{badge_url}" alt="badge">'
|
30 |
|
31 |
+
badge_preview = f"""
|
32 |
+
<div style='padding:20px; background: #fefefe; border-radius: 12px; display: flex; justify-content: center;'>
|
33 |
+
{html_code}
|
|
|
34 |
</div>
|
35 |
"""
|
36 |
+
return html_code, badge_preview
|
37 |
|
38 |
+
# ---------------------------
|
39 |
+
# Gradio UI ๊ตฌ์ฑ
|
40 |
+
# ---------------------------
|
41 |
+
with gr.Blocks(theme=gr.themes.Default()) as demo:
|
42 |
+
gr.HTML("""
|
43 |
+
<h1 style="text-align: center; font-size: 2.2em; margin-bottom: 0.2em;">๐จ BadgeCraft - Beautiful Badge Generator</h1>
|
44 |
+
<p style="text-align: center; font-size: 1.1em; color: #555;">Design stylish shields.io badges with live preview and HTML snippet generation.</p>
|
45 |
+
""")
|
46 |
|
47 |
+
# ์ถ๋ ฅ ์ปดํฌ๋ํธ
|
48 |
+
out_code = gr.Code(label="HTML Snippet", language="html")
|
49 |
+
out_preview = gr.HTML(label="Badge Preview")
|
50 |
+
|
51 |
+
# ์
๋ ฅ ์ปดํฌ๋ํธ
|
|
|
52 |
with gr.Row():
|
53 |
+
label = gr.Textbox(label="Label", placeholder="์: build")
|
54 |
+
message = gr.Textbox(label="Message", placeholder="์: passing")
|
55 |
+
logo = gr.Textbox(label="Logo", placeholder="์: github")
|
56 |
with gr.Row():
|
57 |
+
color = gr.ColorPicker(label="Color", value="#a0c4ff")
|
58 |
+
label_color = gr.ColorPicker(label="Label Color", value="#bdb2ff")
|
59 |
+
logo_color = gr.ColorPicker(label="Logo Color", value="#ffc6ff")
|
60 |
+
style = gr.Dropdown(label="Style", choices=["flat", "flat-square", "plastic", "for-the-badge", "social"], value="for-the-badge")
|
61 |
+
link = gr.Textbox(label="Link (๋ฐฐ์ง ํด๋ฆญ ์ ์ด๋ํ URL)", placeholder="https://yourlink.com")
|
|
|
|
|
62 |
|
63 |
+
# Examples ์ ์ (8๊ฐ ํ๋ ์์๋๋ก)
|
64 |
+
examples = [
|
65 |
+
["Discord", "OpenFree AI", "OpenFree AI", "", "discord", "white", "for-the-badge", "https://discord.gg/openfreeai"],
|
66 |
+
["X.com", "OpenFree AI", "OpenFree AI", "", "X", "white", "for-the-badge", "https://x.com/openfree_ai"],
|
67 |
+
["Collections", "OpenFree AI", "", "", "huggingface", "black", "for-the-badge", "https://huggingface.co/collections/VIDraft/best-open-ai-services-68057e6e312880ea92abaf4c"],
|
68 |
+
["GitHub", "OpenFree AI", "", "", "github", "white", "for-the-badge", "https://github.com/openrunai"],
|
69 |
+
["YouTube", "๋์ ์ ํ๋ธ ์ฑ๋", "#FF0000", "", "youtube", "white", "for-the-badge", "https://www.youtube.com/@AITechTree"],
|
70 |
+
["Facebook", "OpenFree AI", "", "", "Facebook", "black", "for-the-badge", "https://www.facebook.com/profile.php?id=61575353674679"],
|
71 |
+
["Instagram", "OpenFree AI", "", "", "Instagram", "white", "for-the-badge", "https://www.instagram.com/openfree_ai/"],
|
72 |
+
["Threads", "ไฝ ๅฅฝ", "#FF0000", "", "Threads", "white", "for-the-badge", "https://www.threads.net/@openfree_ai"],
|
73 |
+
]
|
74 |
+
gr.HTML("<h3 style='text-align:center; margin-top:20px;'>โจ Examples (ํด๋ฆญํ๋ฉด ์๋ ์
๋ ฅ)</h3>")
|
75 |
+
gr.Examples(
|
76 |
+
examples=examples,
|
77 |
+
inputs=[label, message, color, label_color, logo, logo_color, style, link],
|
78 |
+
outputs=[out_code, out_preview],
|
79 |
+
fn=generate_static_badge,
|
80 |
+
cache_examples=False,
|
81 |
+
run_on_click=True,
|
82 |
+
)
|
83 |
|
84 |
+
# ์ค์๊ฐ change ์ด๋ฒคํธ ๋ฐ์ธ๋ฉ
|
85 |
+
inputs = [label, message, color, label_color, logo, logo_color, style, link]
|
86 |
for inp in inputs:
|
87 |
+
inp.change(fn=generate_static_badge, inputs=inputs, outputs=[out_code, out_preview])
|
88 |
|
89 |
+
# ์คํ
|
90 |
+
if __name__ == "__main__":
|
91 |
+
demo.launch()
|