File size: 16,966 Bytes
d64466a
 
 
18d8ce4
98acb26
18d8ce4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d64466a
 
2c52707
 
 
 
 
d5ad155
2c52707
d5ad155
2c52707
 
 
d5ad155
2c52707
 
74b1c72
2c52707
18d8ce4
 
 
 
 
 
 
d64466a
18d8ce4
2c52707
18d8ce4
 
 
2c52707
 
 
 
d64466a
d5ad155
18d8ce4
 
 
71f31bd
18d8ce4
d64466a
98acb26
18d8ce4
 
 
2c52707
18d8ce4
 
 
 
 
 
 
 
2c52707
18d8ce4
 
 
 
 
 
 
 
2c52707
18d8ce4
 
 
2c52707
18d8ce4
 
 
 
 
2c52707
18d8ce4
 
 
2c52707
18d8ce4
 
 
 
2c52707
18d8ce4
 
 
 
2c52707
18d8ce4
 
 
2c52707
18d8ce4
 
 
 
 
2c52707
18d8ce4
 
 
 
 
 
 
2c52707
18d8ce4
 
 
 
 
 
2c52707
18d8ce4
 
 
 
 
 
 
 
2c52707
18d8ce4
 
 
 
d5ad155
18d8ce4
 
2c52707
18d8ce4
 
2c52707
98acb26
18d8ce4
 
 
 
2c52707
18d8ce4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71f31bd
98acb26
 
18d8ce4
2c52707
18d8ce4
2c52707
 
18d8ce4
2c52707
 
18d8ce4
 
 
 
 
 
 
 
 
 
 
 
 
 
2c52707
 
18d8ce4
2c52707
 
18d8ce4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2c52707
18d8ce4
2c52707
18d8ce4
2c52707
d5ad155
18d8ce4
 
2c52707
18d8ce4
2c52707
d5ad155
18d8ce4
 
2c52707
 
18d8ce4
2c52707
 
18d8ce4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2c52707
 
 
18d8ce4
2c52707
 
18d8ce4
 
 
2c52707
 
d64466a
18d8ce4
 
 
d64466a
18d8ce4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
import urllib.parse
import gradio as gr

# -------------------------------------------------
# Badge URL generation
#   โ””โ–ถ HEX ์ปฌ๋Ÿฌ ์•ž์˜ โ€˜#โ€™ ๊ธฐํ˜ธ๋ฅผ ์ œ๊ฑฐํ•˜์—ฌ Shields.io ๊ฐ€
#      ์ƒ‰์ƒ์„ ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ์ธ์‹ํ•˜๋„๋ก ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค.
# -------------------------------------------------
def generate_static_badge(
    label, message,
    color, label_color,
    logo, logo_color,
    style, link
):
    # 1) ColorPicker ๊ฐ’์—์„œ โ€˜#โ€™ ์ œ๊ฑฐ
    strip_hash = lambda c: c.lstrip("#") if isinstance(c, str) else c
    color       = strip_hash(color)
    label_color = strip_hash(label_color)
    logo_color  = strip_hash(logo_color)

    # 2) Shields.io ์ฟผ๋ฆฌ ํŒŒ๋ผ๋ฏธํ„ฐ ๊ตฌ์„ฑ
    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 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='')}")
    if style:
        params.append(f"style={urllib.parse.quote(style, safe='')}")

    badge_url = base + ("?" + "&".join(params) if params else "")
    html_img  = f'<img src="{badge_url}" alt="badge">'

    # 3) ๋งํฌ ๊ฐ์Œ€์ง€ ์—ฌ๋ถ€
    html_code = (
        f'<a href="{link}" target="_blank">{html_img}</a>'
        if link else html_img
    )

    # 4) ๋ฏธ๋ฆฌ๋ณด๊ธฐ ์นด๋“œ
    badge_preview = f"""
    <div style='padding:30px; background:linear-gradient(135deg,#f8f9fa,#e9ecef);
         border-radius:16px; display:flex; justify-content:center;
         box-shadow:0 6px 12px rgba(0,0,0,0.05);'>
        {html_code}
    </div>
    """
    return html_code, badge_preview


# -------------------------------------------------
# Gradio UI
# -------------------------------------------------
with gr.Blocks(theme=gr.themes.Soft()) as demo:
    # ---------- Global CSS ----------
    gr.HTML("""
    <style>
      body{
        background:linear-gradient(120deg,#f8f9fa,#e2eafc);
        font-family:'Poppins','Noto Sans KR',sans-serif;
      }
      .gradio-container{
        background:rgba(255,255,255,.85);
        backdrop-filter:blur(10px);
        border-radius:20px;
        padding:24px;
        box-shadow:0 10px 30px rgba(0,0,0,.08);
        max-width:1000px;
        margin:0 auto;
      }
      .gr-button{
        background:linear-gradient(135deg,#a8dadc,#88c1e9)!important;
        color:#1d3557!important;
        border:none!important;
        border-radius:10px!important;
        font-weight:600!important;
        transition:all .3s ease!important;
        box-shadow:0 4px 10px rgba(138,198,209,.3)!important;
      }
      .gr-button:hover{
        transform:translateY(-2px)!important;
        box-shadow:0 6px 15px rgba(138,198,209,.4)!important;
      }
      .gr-textbox,.gr-select,.gr-color{
        background:#e8f6f3!important;
        border:2px solid #d9f0ea!important;
        border-radius:12px!important;
        transition:all .3s ease!important;
      }
      .gr-textbox:focus,.gr-select:focus,.gr-color:focus{
        border-color:#a8dadc!important;
        box-shadow:0 0 0 3px rgba(168,218,220,.25)!important;
      }
      label.block span{
        color:#457b9d!important;
        font-weight:600!important;
        font-size:1rem!important;
      }
      h1{
        color:#5e60ce;
        font-weight:800;
        letter-spacing:-.5px;
      }
      h3{
        color:#5e60ce;
        font-weight:600;
      }
      .footer{
        margin-top:30px;
        text-align:center;
        font-size:.9rem;
        color:#6d6875;
      }
      .badge-section{
        background:rgba(255,255,255,.7);
        border-radius:16px;
        padding:20px;
        box-shadow:0 4px 12px rgba(0,0,0,.03);
        margin-bottom:24px;
        border:1px solid rgba(230,240,255,.7);
      }
      .example-grid{
        display:grid;
        grid-template-columns:repeat(4,1fr);
        grid-template-rows:repeat(2,auto);
        gap:16px;
        margin-top:20px;
      }
      .example-item{
        background:linear-gradient(135deg,#f1f8ff,#e8f4ff);
        border-radius:12px;
        padding:16px;
        text-align:center;
        cursor:pointer;
        transition:all .3s ease;
        border:2px solid transparent;
      }
      .example-item:hover{
        transform:translateY(-3px);
        box-shadow:0 8px 15px rgba(0,0,0,.05);
        border-color:#a8dadc;
      }
      @media(max-width:768px){
        .example-grid{grid-template-columns:repeat(2,1fr);}
      }
      @media(max-width:600px){
        .example-grid{grid-template-columns:1fr;}
      }
    </style>
    """)

    # ---------- Header ----------
    gr.HTML("""
    <div style="text-align:center; margin-bottom:24px;">
      <h1 style="font-size:2.8rem; margin-bottom:.2em;
                 background:linear-gradient(90deg,#5e60ce,#64dfdf);
                 -webkit-background-clip:text;-webkit-text-fill-color:transparent;">
        ๐ŸŽจ BadgeCraft
      </h1>
      <p style="font-size:1.2rem; margin:.5em 0; color:#457b9d;
                max-width:700px; margin:0 auto;">
        Create beautiful badges with live preview and HTML snippet
      </p>
      <div style="margin-top:10px; display:flex; justify-content:center;
                  gap:12px; flex-wrap:wrap;">
        <span style="display:inline-block; background:#e9f5db; color:#588157;
                     padding:6px 12px; border-radius:30px; font-size:.9rem;">
          <strong>โœจ MIT License</strong>
        </span>
        <span style="display:inline-block; background:#d8f3dc; color:#2d6a4f;
                     padding:6px 12px; border-radius:30px; font-size:.9rem;">
          <strong>๐Ÿ‘ฅ Created by OpenFreeAI Team</strong>
        </span>
      </div>
    </div>
    """)

    # ---------- Tabs ----------
    with gr.Tabs():
        # โ–ทโ–ท Badge Generator ํƒญ
        with gr.TabItem("Badge Generator"):
            with gr.Row():
                # ----- ์„ค์ • ์ž…๋ ฅ -----
                with gr.Column():
                    with gr.Group(elem_classes="badge-section"):
                        gr.HTML("<h3 style='margin-top:0;margin-bottom:16px;font-size:1.3rem;'>โœ๏ธ Badge Settings</h3>")
                        label       = gr.Textbox(label="Label",  value="Discord", lines=1, elem_id="label-input")
                        message     = gr.Textbox(label="Message", value="Join our community", lines=1, elem_id="message-input")
                        logo        = gr.Textbox(label="Logo", value="discord", lines=1, elem_id="logo-input")
                        style       = gr.Dropdown(
                                          label="Style",
                                          choices=["flat","flat-square","plastic","for-the-badge","social"],
                                          value="for-the-badge",
                                          elem_id="style-input")
                        color       = gr.ColorPicker(label="Background Color", value="#5865F2", elem_id="color-input")
                        label_color = gr.ColorPicker(label="Label Background Color", value="#99AAFF", elem_id="label-color-input")
                        logo_color  = gr.ColorPicker(label="Logo Color", value="#ffffff", elem_id="logo-color-input")
                        link        = gr.Textbox(label="Link (URL)", value="https://discord.gg/openfreeai", lines=1, elem_id="link-input")
                # ----- ๋ฏธ๋ฆฌ๋ณด๊ธฐ & ์ฝ”๋“œ -----
                with gr.Column():
                    with gr.Group(elem_classes="badge-section"):
                        gr.HTML("<h3 style='margin-top:0;margin-bottom:16px;font-size:1.3rem;'>๐Ÿ‘๏ธ Preview</h3>")
                        out_preview = gr.HTML(label="")
                    with gr.Group(elem_classes="badge-section"):
                        gr.HTML("<h3 style='margin-top:0;margin-bottom:16px;font-size:1.3rem;'>๐Ÿ’ป HTML Code</h3>")
                        out_code    = gr.Code(label="", language="html", lines=3)

            # ์˜ˆ์ œ ๋ฐ์ดํ„ฐ
            examples = [
                ["Discord",    "Openfreeย AI", "#5865F2", "#99AAFF", "discord",    "white", "for-the-badge", "https://discord.gg/openfreeai"],
                ["X.com",      "Follow us",   "#1DA1F2", "#00CFFF", "x",          "white", "for-the-badge", "https://x.com/openfree_ai"],
                ["Collections","Explore",     "#FFB300", "#FFF176", "huggingface","black", "for-the-badge", "https://huggingface.co/collections/VIDraft/best-open-ai-services-68057e6e312880ea92abaf4c"],
                ["GitHub",     "Star us",     "#0A0A0A", "#39FF14", "github",     "white", "for-the-badge", "https://github.com/openfreeai"],
                ["YouTube",    "Watch now",   "#E50000", "#FF5E5E", "youtube",    "white", "for-the-badge", "https://www.youtube.com/@AITechTree"],
                ["Facebook",   "Like us",     "#1877F2", "#6FAFFF", "facebook",   "white", "for-the-badge", "https://www.facebook.com/profile.php?id=61575353674679"],
                ["Instagram",  "ๅ‹ๆƒ… ่ฌไธ–",     "#E4405F", "#FF77A9", "instagram",  "white", "for-the-badge", "https://www.instagram.com/openfree_ai/"],
                ["Threads",    "ํ•จ๊ป˜ ์ฆ๊ฒจ์š”.", "#000000", "#FF00FF", "threads",    "white", "for-the-badge", "https://www.threads.net/@openfree_ai"],
            ]

            # ์˜ˆ์ œ ๊ทธ๋ฆฌ๋“œ HTML
            html_items = '<div class="example-grid">'
            for idx, ex in enumerate(examples):
                badge_url = (
                    "https://img.shields.io/static/v1?" + "&".join([
                        f"label={urllib.parse.quote(ex[0],safe='')}",
                        f"message={urllib.parse.quote(ex[1],safe='')}",
                        f"color={urllib.parse.quote(ex[2].lstrip('#'),safe='')}",
                        f"labelColor={urllib.parse.quote(ex[3].lstrip('#'),safe='')}",
                        f"logo={urllib.parse.quote(ex[4],safe='')}",
                        f"logoColor={urllib.parse.quote(ex[5],safe='')}",
                        f"style={urllib.parse.quote(ex[6],safe='')}"
                    ])
                )
                html_items += f'''
                <div class="example-item" onclick="applyExample({idx})">
                  <img src="{badge_url}" alt="{ex[0]} badge" style="margin-bottom:8px;">
                  <div style="font-size:.9rem;color:#457b9d;">{ex[0]}</div>
                </div>
                '''
            html_items += '</div>'

            # ------------- React Controlled Input Hack -------------
            hack_js = """
            function updateReactValue(el,newVal){
              if(!el)return;
              let prototype=window.HTMLInputElement.prototype;
              if(el.tagName==="TEXTAREA")prototype=window.HTMLTextAreaElement.prototype;
              const descriptor=Object.getOwnPropertyDescriptor(prototype,"value");
              descriptor.set.call(el,newVal);
              el.dispatchEvent(new Event("input",{bubbles:true}));
              el.dispatchEvent(new Event("change",{bubbles:true}));
            }
            function convertToHexIfNeeded(c){
              if(!c)return"#000000";
              if(c.toLowerCase()==="white")return"#ffffff";
              if(c.toLowerCase()==="black")return"#000000";
              return c;
            }
            function setColorValue(elemId,val){
              const container=document.getElementById(elemId);
              if(!container)return;
              let input=container.querySelector("input[type='color']");
              if(!input)input=container.querySelector("input[type='text']");
              if(!input)return;
              updateReactValue(input,val);
            }
            """

            # ์˜ˆ์ œ ํด๋ฆญ ์‹œ ์ž๋™ ์ฑ„์šฐ๊ธฐ
            apply_example_js = f"""
            <script>
            {hack_js}
            const examples={examples};
            function applyExample(i){{
              const ex=examples[i];
              const labelBox=document.querySelector("#label-input textarea,#label-input input");
              if(labelBox)updateReactValue(labelBox,ex[0]);
              const msgBox=document.querySelector("#message-input textarea,#message-input input");
              if(msgBox)updateReactValue(msgBox,ex[1]);
              setColorValue("color-input",convertToHexIfNeeded(ex[2]));
              setColorValue("label-color-input",convertToHexIfNeeded(ex[3]));
              const logoBox=document.querySelector("#logo-input textarea,#logo-input input");
              if(logoBox)updateReactValue(logoBox,ex[4]);
              setColorValue("logo-color-input",convertToHexIfNeeded(ex[5]));
              const styleSel=document.querySelector("#style-input select");
              if(styleSel){styleSel.value=ex[6];styleSel.dispatchEvent(new Event("change",{bubbles:true}));}
              const linkBox=document.querySelector("#link-input textarea,#link-input input");
              if(linkBox)updateReactValue(linkBox,ex[7]);
            }}
            </script>
            """

            gr.HTML(html_items + apply_example_js)

            # ---------- ์ดˆ๊ธฐ ๋กœ๋“œ & ์‹ค์‹œ๊ฐ„ ์—…๋ฐ์ดํŠธ ----------
            demo.load(
                fn=generate_static_badge,
                inputs=[label,message,color,label_color,logo,logo_color,style,link],
                outputs=[out_code,out_preview]
            )
            for inp in [label,message,color,label_color,logo,logo_color,style,link]:
                inp.change(
                    fn=generate_static_badge,
                    inputs=[label,message,color,label_color,logo,logo_color,style,link],
                    outputs=[out_code,out_preview]
                )

        # โ–ทโ–ท Help ํƒญ
        with gr.TabItem("Help"):
            gr.HTML('''
            <div style="padding:20px;background:rgba(255,255,255,.7);
                        border-radius:16px;box-shadow:0 4px 12px rgba(0,0,0,.03);">
              <h3 style="color:#5e60ce;margin-top:0;">๐Ÿ“‹ How to Use BadgeCraft</h3>
              <h4 style="color:#457b9d;margin-bottom:8px;">โœจ What are Badges?</h4>
              <p>Badges are small visual indicators that can be used in README files, websites, and documentation. Shields.io badges are widely used to display project status, social media links, version information, and more.</p>
              <h4 style="color:#457b9d;margin-bottom:8px;">๐Ÿ› ๏ธ Basic Settings</h4>
              <ul>
                <li><strong>Label</strong>: Text displayed on the left side of the badge (e.g., "Discord", "Version", "Status")</li>
                <li><strong>Message</strong>: Text displayed on the right side of the badge</li>
                <li><strong>Logo</strong>: Name of a logo provided by Simple Icons (<a href="https://simpleicons.org/" target="_blank">View List</a>)</li>
                <li><strong>Style</strong>: Determines the shape of the badge (flat, plastic, for-the-badge, etc.)</li>
              </ul>
              <h4 style="color:#457b9d;margin-bottom:8px;">๐ŸŽจ Color Settings</h4>
              <ul>
                <li><strong>Background Color</strong>: Background color for the right side of the badge</li>
                <li><strong>Label Background Color</strong>: Background color for the left side of the badge</li>
                <li><strong>Logo Color</strong>: Color of the logo (e.g. white or black)</li>
              </ul>
              <h4 style="color:#457b9d;margin-bottom:8px;">๐Ÿ”— Using the HTML</h4>
              <p>Copy the generated HTML code and paste it into your website, blog, GitHub README, etc.</p>
              <p>HTML works in GitHub READMEs, but if you prefer markdown, use <code>![alt text](badge URL)</code>.</p>
              <h4 style="color:#457b9d;margin-bottom:8px;">๐Ÿ’ก Tips</h4>
              <ul>
                <li>Click on any example in the grid to automatically fill in all settings</li>
                <li>The preview updates in real-time as you make changes</li>
                <li>You can use over 2000+ logos from Simple Icons โ€” just enter the name</li>
                <li>Custom colors can be selected with the color picker or by entering a hex code</li>
              </ul>
            </div>
            ''')

    # ---------- Footer ----------
    gr.HTML('''
    <div class="footer">
      <p>ยฉ 2023โ€‘2025 BadgeCraft | MIT Licenseย ย |
         <a href="https://discord.gg/openfreeai" target="_blank" style="color:#5e60ce;">Discord</a>
      </p>
    </div>
    ''')

# -------------------------------------------------
# Launch
# -------------------------------------------------
if __name__ == "__main__":
    demo.launch()