openfree commited on
Commit
5f1b74f
·
verified ·
1 Parent(s): eaae140

Delete app-backup.py

Browse files
Files changed (1) hide show
  1. app-backup.py +0 -419
app-backup.py DELETED
@@ -1,419 +0,0 @@
1
- import urllib.parse
2
- import gradio as gr
3
-
4
- # ---------------------------
5
- # Badge URL generation
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:
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 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:30px; background: linear-gradient(135deg, #f8f9fa, #e9ecef);
33
- border-radius: 16px; display: flex; justify-content: center;
34
- box-shadow: 0 6px 12px rgba(0,0,0,0.05);'>
35
- {html_code}
36
- </div>
37
- """
38
- return html_code, badge_preview
39
-
40
- # ---------------------------
41
- # Gradio UI
42
- # ---------------------------
43
- with gr.Blocks(theme=gr.themes.Soft()) as demo:
44
- # Custom CSS
45
- gr.HTML("""
46
- <style>
47
- body {
48
- background: linear-gradient(120deg, #f8f9fa, #e2eafc);
49
- font-family: 'Poppins', 'Noto Sans KR', sans-serif;
50
- }
51
- .gradio-container {
52
- background: rgba(255, 255, 255, 0.85);
53
- backdrop-filter: blur(10px);
54
- border-radius: 20px;
55
- padding: 24px;
56
- box-shadow: 0 10px 30px rgba(0,0,0,0.08);
57
- max-width: 1000px;
58
- margin: 0 auto;
59
- }
60
- .gr-button {
61
- background: linear-gradient(135deg, #a8dadc, #88c1e9) !important;
62
- color: #1d3557 !important;
63
- border: none !important;
64
- border-radius: 10px !important;
65
- font-weight: 600 !important;
66
- transition: all 0.3s ease !important;
67
- box-shadow: 0 4px 10px rgba(138, 198, 209, 0.3) !important;
68
- }
69
- .gr-button:hover {
70
- transform: translateY(-2px) !important;
71
- box-shadow: 0 6px 15px rgba(138, 198, 209, 0.4) !important;
72
- }
73
- .gr-textbox, .gr-select, .gr-color {
74
- background: #e8f6f3 !important;
75
- border: 2px solid #d9f0ea !important;
76
- border-radius: 12px !important;
77
- transition: all 0.3s ease !important;
78
- }
79
- .gr-textbox:focus, .gr-select:focus, .gr-color:focus {
80
- border-color: #a8dadc !important;
81
- box-shadow: 0 0 0 3px rgba(168, 218, 220, 0.25) !important;
82
- }
83
- label.block span {
84
- color: #457b9d !important;
85
- font-weight: 600 !important;
86
- font-size: 1rem !important;
87
- }
88
- h1 {
89
- color: #5e60ce;
90
- font-weight: 800;
91
- letter-spacing: -0.5px;
92
- }
93
- h3 {
94
- color: #5e60ce;
95
- font-weight: 600;
96
- }
97
- .footer {
98
- margin-top: 30px;
99
- text-align: center;
100
- font-size: 0.9rem;
101
- color: #6d6875;
102
- }
103
- .badge-section {
104
- background: rgba(255, 255, 255, 0.7);
105
- border-radius: 16px;
106
- padding: 20px;
107
- box-shadow: 0 4px 12px rgba(0,0,0,0.03);
108
- margin-bottom: 24px;
109
- border: 1px solid rgba(230, 240, 255, 0.7);
110
- }
111
- .example-grid {
112
- display: grid;
113
- grid-template-columns: repeat(4, 1fr);
114
- grid-template-rows: repeat(2, auto);
115
- gap: 16px;
116
- margin-top: 20px;
117
- }
118
- .example-item {
119
- background: linear-gradient(135deg, #f1f8ff, #e8f4ff);
120
- border-radius: 12px;
121
- padding: 16px;
122
- text-align: center;
123
- cursor: pointer;
124
- transition: all 0.3s ease;
125
- border: 2px solid transparent;
126
- }
127
- .example-item:hover {
128
- transform: translateY(-3px);
129
- box-shadow: 0 8px 15px rgba(0,0,0,0.05);
130
- border-color: #a8dadc;
131
- }
132
- @media (max-width: 768px) {
133
- .example-grid {
134
- grid-template-columns: repeat(2, 1fr);
135
- }
136
- }
137
- @media (max-width: 600px) {
138
- .example-grid {
139
- grid-template-columns: 1fr;
140
- }
141
- }
142
- .color-preview {
143
- display: inline-block;
144
- width: 20px;
145
- height: 20px;
146
- margin-right: 5px;
147
- border-radius: 4px;
148
- vertical-align: middle;
149
- }
150
- </style>
151
- """)
152
-
153
- # Header section
154
- gr.HTML("""
155
- <div style="text-align:center; margin-bottom:24px;">
156
- <h1 style="font-size:2.8rem; margin-bottom:0.2em; background: linear-gradient(90deg, #5e60ce, #64dfdf); -webkit-background-clip: text; -webkit-text-fill-color: transparent;">
157
- 🎨 BadgeCraft
158
- </h1>
159
- <p style="font-size:1.2rem; margin:0.5em 0; color:#457b9d; max-width:700px; margin:0 auto;">
160
- Create beautiful badges with live preview and HTML snippet
161
- </p>
162
- <div style="margin-top:10px; display:flex; justify-content:center; gap:12px; flex-wrap:wrap;">
163
- <span style="display:inline-block; background:#e9f5db; color:#588157; padding:6px 12px; border-radius:30px; font-size:0.9rem;">
164
- <strong>✨ MIT License</strong>
165
- </span>
166
- <span style="display:inline-block; background:#d8f3dc; color:#2d6a4f; padding:6px 12px; border-radius:30px; font-size:0.9rem;">
167
- <strong>👥 Created by OpenFreeAI Team</strong>
168
- </span>
169
- </div>
170
- </div>
171
- """)
172
-
173
- # Define color options
174
- color_options = {
175
- "Red": "#ff0000",
176
- "Blue": "#0000ff",
177
- "Green": "#00ff00",
178
- "Yellow": "#ffff00",
179
- "Purple": "#800080",
180
- "Orange": "#ffa500",
181
- "Pink": "#ffc0cb",
182
- "Teal": "#008080",
183
- "Navy": "#000080",
184
- "Lime": "#00ff00",
185
- "Cyan": "#00ffff",
186
- "Magenta": "#ff00ff",
187
- "Gold": "#ffd700",
188
- "Silver": "#c0c0c0"
189
- }
190
-
191
- with gr.Tabs():
192
- with gr.TabItem("Badge Generator"):
193
- with gr.Row():
194
- with gr.Column():
195
- with gr.Group(elem_classes="badge-section"):
196
- gr.HTML("<h3 style='margin-top:0; margin-bottom:16px; font-size:1.3rem;'>✏️ Badge Settings</h3>")
197
- label = gr.Textbox(label="Label", value="Discord", elem_id="label-input", lines=1)
198
- message = gr.Textbox(label="Message", value="Join our community", elem_id="message-input", lines=1)
199
- logo = gr.Textbox(label="Logo", value="discord", elem_id="logo-input", lines=1)
200
- style = gr.Dropdown(
201
- label="Style",
202
- choices=["flat", "flat-square", "plastic", "for-the-badge", "social"],
203
- value="for-the-badge",
204
- elem_id="style-input"
205
- )
206
-
207
- # Replace color pickers with dropdown selections
208
- color_choices = [f"<div><span class='color-preview' style='background-color:{hex_code}'></span>{name}</div>" for name, hex_code in color_options.items()]
209
- color = gr.Dropdown(
210
- label="Background Color",
211
- choices=list(color_options.keys()),
212
- value="Blue",
213
- elem_id="color-input"
214
- )
215
- label_color = gr.Dropdown(
216
- label="Label Background Color",
217
- choices=list(color_options.keys()),
218
- value="Purple",
219
- elem_id="label-color-input"
220
- )
221
- logo_color = gr.Dropdown(
222
- label="Logo Color",
223
- choices=["white", "black"] + list(color_options.keys()),
224
- value="white",
225
- elem_id="logo-color-input"
226
- )
227
- link = gr.Textbox(label="Link (URL)", value="https://discord.gg/openfreeai", elem_id="link-input", lines=1)
228
- with gr.Column():
229
- with gr.Group(elem_classes="badge-section"):
230
- gr.HTML("<h3 style='margin-top:0; margin-bottom:16px; font-size:1.3rem;'>👁️ Preview</h3>")
231
- out_preview = gr.HTML(label="")
232
- with gr.Group(elem_classes="badge-section"):
233
- gr.HTML("<h3 style='margin-top:0; margin-bottom:16px; font-size:1.3rem;'>💻 HTML Code</h3>")
234
- out_code = gr.Code(label="", language="html", lines=3)
235
-
236
- # 예제 리스트 (label, message, bg_color, label_color, logo, logo_color, style, link)
237
- examples = [
238
- ["Discord", "Openfree AI", "Blue", "Purple", "discord", "white", "for-the-badge", "https://discord.gg/openfreeai"],
239
- ["X.com", "Follow us", "Blue", "Cyan", "x", "white", "for-the-badge", "https://x.com/openfree_ai"],
240
- ["Collections","Explore", "Orange", "Yellow", "huggingface","black","for-the-badge", "https://huggingface.co/collections/VIDraft/best-open-ai-services-68057e6e312880ea92abaf4c"],
241
- ["GitHub", "Star us", "Navy", "Lime", "github", "white", "for-the-badge", "https://github.com/openfreeai"],
242
- ["YouTube", "Watch now", "Red", "Orange", "youtube", "white", "for-the-badge", "https://www.youtube.com/@AITechTree"],
243
- ["Facebook", "Like us", "Blue", "Cyan", "facebook", "white", "for-the-badge", "https://www.facebook.com/profile.php?id=61575353674679"],
244
- ["Instagram", "友情 萬世", "Magenta", "Pink", "instagram", "white", "for-the-badge", "https://www.instagram.com/openfree_ai/"],
245
- ["Threads", "함께 즐겨요.", "Navy", "Magenta", "threads", "white", "for-the-badge", "https://www.threads.net/@openfree_ai"],
246
- ]
247
-
248
- # 예제 미리보기
249
- html_items = '<div class="example-grid">'
250
- for idx, ex in enumerate(examples):
251
- # ex = [label, message, bg_color, label_color, logo, logo_color, style, link]
252
- color_hex = color_options.get(ex[2], ex[2])
253
- label_color_hex = color_options.get(ex[3], ex[3])
254
- logo_color_val = color_options.get(ex[5], ex[5]) if ex[5] in color_options else ex[5]
255
-
256
- badge_url = (
257
- "https://img.shields.io/static/v1?" + "&".join([
258
- f"label={urllib.parse.quote(ex[0], safe='')}",
259
- f"message={urllib.parse.quote(ex[1], safe='')}",
260
- f"color={urllib.parse.quote(color_hex, safe='')}",
261
- f"labelColor={urllib.parse.quote(label_color_hex, safe='')}",
262
- f"logo={urllib.parse.quote(ex[4], safe='')}",
263
- f"logoColor={urllib.parse.quote(logo_color_val, safe='')}",
264
- f"style={urllib.parse.quote(ex[6], safe='')}"
265
- ])
266
- )
267
- html_items += f'''
268
- <div class="example-item" onclick="applyExample({idx})">
269
- <img src="{badge_url}" alt="{ex[0]} badge" style="margin-bottom:8px;">
270
- <div style="font-size:0.9rem; color:#457b9d;">{ex[0]}</div>
271
- </div>
272
- '''
273
- html_items += '</div>'
274
-
275
- # 예제를 클릭했을 때 적용하는 main 함수
276
- apply_example_js = """
277
- <script>
278
- function updateSelectValue(selectEl, newValue) {
279
- if (!selectEl) return;
280
- selectEl.value = newValue;
281
- selectEl.dispatchEvent(new Event("change", { bubbles: true }));
282
- }
283
-
284
- function updateTextValue(el, newValue) {
285
- if (!el) return;
286
- el.value = newValue;
287
- el.dispatchEvent(new Event("input", { bubbles: true }));
288
- el.dispatchEvent(new Event("change", { bubbles: true }));
289
- }
290
-
291
- const examples = """ + str(examples).replace("'", '"') + """;
292
-
293
- function applyExample(i) {
294
- const ex = examples[i];
295
- // ex = [label, message, bg_color, label_color, logo, logo_color, style, link]
296
-
297
- // Label
298
- const labelBox = document.querySelector("#label-input textarea, #label-input input");
299
- if (labelBox) {
300
- updateTextValue(labelBox, ex[0]);
301
- }
302
-
303
- // Message
304
- const msgBox = document.querySelector("#message-input textarea, #message-input input");
305
- if (msgBox) {
306
- updateTextValue(msgBox, ex[1]);
307
- }
308
-
309
- // Background Color (Dropdown)
310
- const bgColorSelect = document.querySelector("#color-input select");
311
- if (bgColorSelect) {
312
- updateSelectValue(bgColorSelect, ex[2]);
313
- }
314
-
315
- // Label Background Color (Dropdown)
316
- const labelColorSelect = document.querySelector("#label-color-input select");
317
- if (labelColorSelect) {
318
- updateSelectValue(labelColorSelect, ex[3]);
319
- }
320
-
321
- // Logo
322
- const logoBox = document.querySelector("#logo-input textarea, #logo-input input");
323
- if (logoBox) {
324
- updateTextValue(logoBox, ex[4]);
325
- }
326
-
327
- // Logo Color (Dropdown)
328
- const logoColorSelect = document.querySelector("#logo-color-input select");
329
- if (logoColorSelect) {
330
- updateSelectValue(logoColorSelect, ex[5]);
331
- }
332
-
333
- // Style (Dropdown)
334
- const styleSelect = document.querySelector("#style-input select");
335
- if (styleSelect) {
336
- updateSelectValue(styleSelect, ex[6]);
337
- }
338
-
339
- // Link
340
- const linkBox = document.querySelector("#link-input textarea, #link-input input");
341
- if (linkBox) {
342
- updateTextValue(linkBox, ex[7]);
343
- }
344
- }
345
- </script>
346
- """
347
-
348
- gr.HTML(html_items + apply_example_js)
349
-
350
- # 함수를 수정하여 색상 값을 변환
351
- def process_badge(label, message, color_name, label_color_name, logo, logo_color_name, style, link):
352
- # 색상 이름을 hex 코드로 변환
353
- color_hex = color_options.get(color_name, "#000000")
354
- label_color_hex = color_options.get(label_color_name, "#000000")
355
-
356
- # logo_color가 white나 black인 경우 그대로 사용, 아니면 hex 코드로 변환
357
- if logo_color_name in ["white", "black"]:
358
- logo_color_hex = logo_color_name
359
- else:
360
- logo_color_hex = color_options.get(logo_color_name, "#ffffff")
361
-
362
- return generate_static_badge(label, message, color_hex, label_color_hex, logo, logo_color_hex, style, link)
363
-
364
- # 초기/실시간 업데이트
365
- demo.load(
366
- fn=process_badge,
367
- inputs=[label, message, color, label_color, logo, logo_color, style, link],
368
- outputs=[out_code, out_preview]
369
- )
370
- for inp in [label, message, color, label_color, logo, logo_color, style, link]:
371
- inp.change(
372
- fn=process_badge,
373
- inputs=[label, message, color, label_color, logo, logo_color, style, link],
374
- outputs=[out_code, out_preview]
375
- )
376
-
377
- with gr.TabItem("Help"):
378
- gr.HTML('''
379
- <div style="padding: 20px; background: rgba(255, 255, 255, 0.7); border-radius: 16px; box-shadow: 0 4px 12px rgba(0,0,0,0.03);">
380
- <h3 style="color: #5e60ce; margin-top:0;">📋 How to Use BadgeCraft</h3>
381
- <h4 style="color: #457b9d; margin-bottom: 8px;">✨ What are Badges?</h4>
382
- <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>
383
- <h4 style="color: #457b9d; margin-bottom: 8px;">🛠️ Basic Settings</h4>
384
- <ul>
385
- <li><strong>Label</strong>: Text displayed on the left side of the badge (e.g., "Discord", "Version", "Status")</li>
386
- <li><strong>Message</strong>: Text displayed on the right side of the badge</li>
387
- <li><strong>Logo</strong>: Name of a logo provided by Simple Icons (<a href="https://simpleicons.org/" target="_blank">View List</a>)</li>
388
- <li><strong>Style</strong>: Determines the shape of the badge (flat, plastic, for-the-badge, etc.)</li>
389
- </ul>
390
- <h4 style="color: #457b9d; margin-bottom: 8px;">🎨 ColorSettings</h4>
391
- <ul>
392
- <li><strong>Background Color</strong>: Background color for the right side of the badge</li>
393
- <li><strong>Label Background Color</strong>: Background color for the left side of the badge</li>
394
- <li><strong>Logo Color</strong>: Color of the logo (e.g. white or black)</li>
395
- </ul>
396
- <h4 style="color: #457b9d; margin-bottom: 8px;">🔗 Using the HTML</h4>
397
- <p>Copy the generated HTML code and paste it into your website, blog, GitHub README, etc.</p>
398
- <p>HTML works in GitHub READMEs, but if you prefer markdown, use <code>![alt text](badge URL)</code>.</p>
399
- <h4 style="color: #457b9d; margin-bottom: 8px;">💡 Tips</h4>
400
- <ul>
401
- <li>Click on any example in the grid to automatically fill in all settings</li>
402
- <li>The preview updates in real-time as you make changes</li>
403
- <li>You can use over 2000+ logos from Simple Icons - just enter the name</li>
404
- <li>Choose from predefined colors in the dropdown menus for consistent results</li>
405
- </ul>
406
- </div>
407
- ''')
408
-
409
- # Footer
410
- gr.HTML('''
411
- <div class="footer">
412
- <p>© 2023-2025 BadgeCraft | MIT License
413
- <a href="https://discord.gg/openfreeai" target="_blank" style="color:#5e60ce;">Discord</a>
414
- </p>
415
- </div>
416
- ''')
417
-
418
- if __name__ == "__main__":
419
- demo.launch()