fantos commited on
Commit
5c8677b
·
verified ·
1 Parent(s): d27a225

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -62
app.py CHANGED
@@ -23,13 +23,11 @@ def generate_static_badge(label, message, color, label_color, logo, logo_color,
23
  params.append(f"style={urllib.parse.quote(style, safe='')}")
24
 
25
  badge_url = base + ("?" + "&".join(params) if params else "")
26
- # HTML snippet with optional link wrapper
27
  if link:
28
  html_code = f'<a href="{link}" target="_blank"><img src="{badge_url}" alt="badge"></a>'
29
  else:
30
  html_code = f'<img src="{badge_url}" alt="badge">'
31
 
32
- # Badge preview container
33
  badge_preview = f"""
34
  <div style='padding:20px; background: #fefefe; border-radius: 12px; display: flex; justify-content: center;'>
35
  {html_code}
@@ -41,91 +39,72 @@ def generate_static_badge(label, message, color, label_color, logo, logo_color,
41
  # Gradio UI 구성
42
  # ---------------------------
43
  with gr.Blocks(theme=gr.themes.Default()) as demo:
44
- # 서비스 제목 및 설명
45
  gr.HTML("""
46
  <h1 style="text-align: center; font-size: 2.2em; margin-bottom: 0.2em;">🎨 BadgeCraft - Beautiful Badge Generator</h1>
47
  <p style="text-align: center; font-size: 1.1em; color: #555;">Design stylish shields.io badges with live preview and HTML snippet generation.</p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  """)
49
 
50
- # 코드와 미리보기 수평 배치
51
  with gr.Row():
52
  out_code = gr.Code(label="HTML Snippet", language="html")
53
  out_preview = gr.HTML(label="Badge Preview")
54
 
55
- # 사용자 입력 폼: Label, Message, Logo
56
  with gr.Row():
57
  label = gr.Textbox(label="Label", placeholder="예: build")
58
  message = gr.Textbox(label="Message", placeholder="예: passing")
59
  logo = gr.Textbox(label="Logo", placeholder="예: github")
60
 
61
- # 색상 팔레트: Color, Label Color, Logo Color
62
  with gr.Row():
63
  color = gr.ColorPicker(label="Color", value="#a0c4ff")
64
  label_color = gr.ColorPicker(label="Label Color", value="#bdb2ff")
65
  logo_color = gr.ColorPicker(label="Logo Color", value="#ffc6ff")
66
 
67
- # Style 드롭다운 및 링크 입력
68
  style = gr.Dropdown(label="Style", choices=["flat", "flat-square", "plastic", "for-the-badge", "social"], value="for-the-badge")
69
  link = gr.Textbox(label="Link (배지 클릭 시 이동할 URL)", placeholder="https://yourlink.com")
70
 
71
- # 입력값 변경 시 자동 업데이트
72
  inputs = [label, message, color, label_color, logo, logo_color, style, link]
73
  for inp in inputs:
74
  inp.change(fn=generate_static_badge, inputs=inputs, outputs=[out_code, out_preview])
75
 
76
- # 예제 로딩 함수
77
- def load_example(label_val, message_val, logo_val, link_val):
78
- return label_val, message_val, logo_val, link_val
79
-
80
- # Examples 라벨
81
- gr.HTML("""
82
- <h3 style="text-align: center; margin-top: 30px;">✨ Examples (Click to Load)</h3>
83
- """)
84
-
85
- # 예제 버튼들을 한 줄에 배치
86
- with gr.Row():
87
- discord_btn = gr.Button("Discord Badge Example")
88
- x_btn = gr.Button("X Badge Example")
89
- instagram_btn = gr.Button("Instagram Badge Example")
90
- threads_btn = gr.Button("Threads Badge Example")
91
- facebook_btn = gr.Button("Facebook Badge Example")
92
-
93
- # 각 버튼 클릭 시 예제 데이터 로드 및 새탭 열기
94
- discord_btn.click(
95
- fn=lambda: load_example("Discord", "Join", "discord", "https://discord.gg/openfreeai"),
96
- inputs=[], outputs=[label, message, logo, link]
97
- ).then(
98
- lambda: gr.open_url("https://discord.gg/openfreeai"), [], []
99
- )
100
-
101
- x_btn.click(
102
- fn=lambda: load_example("X.com", "Follow", "x", "https://x.com/openfree_ai"),
103
- inputs=[], outputs=[label, message, logo, link]
104
- ).then(
105
- lambda: gr.open_url("https://x.com/openfree_ai"), [], []
106
- )
107
-
108
- instagram_btn.click(
109
- fn=lambda: load_example("Instagram", "Follow", "instagram", "https://www.instagram.com/openfree_ai"),
110
- inputs=[], outputs=[label, message, logo, link]
111
- ).then(
112
- lambda: gr.open_url("https://www.instagram.com/openfree_ai"), [], []
113
- )
114
-
115
- threads_btn.click(
116
- fn=lambda: load_example("Threads", "Follow", "threads", "https://www.threads.net/@openfree_ai"),
117
- inputs=[], outputs=[label, message, logo, link]
118
- ).then(
119
- lambda: gr.open_url("https://www.threads.net/@openfree_ai"), [], []
120
- )
121
-
122
- facebook_btn.click(
123
- fn=lambda: load_example("Facebook", "Like", "facebook", "https://www.facebook.com/profile.php?id=61575353674679"),
124
- inputs=[], outputs=[label, message, logo, link]
125
- ).then(
126
- lambda: gr.open_url("https://www.facebook.com/profile.php?id=61575353674679"), [], []
127
- )
128
-
129
- # 앱 실행
130
  if __name__ == "__main__":
131
  demo.launch()
 
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}
 
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
+ <h3 style="text-align: center; margin-top: 30px;">✨ Examples</h3>
47
+ <div align="center" style="display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; margin: 10px 0 30px; justify-items: center;">
48
+ <a href="https://discord.gg/openfreeai">
49
+ <img alt="Discord" src="https://img.shields.io/badge/Discord-5865F2?style=for-the-badge&logo=discord&logoColor=white" />
50
+ </a>
51
+ <a href="https://x.com/openfree_ai">
52
+ <img alt="X" src="https://img.shields.io/badge/X.com-000000?style=for-the-badge&logo=X&logoColor=white" />
53
+ </a>
54
+ <a href="https://huggingface.co/collections/VIDraft/best-open-ai-services-68057e6e312880ea92abaf4c">
55
+ <img alt="Collections" src="https://img.shields.io/badge/Collections-F8F8F8?style=for-the-badge&logo=huggingface&logoColor=black" />
56
+ </a>
57
+ <a href="https://huggingface.co/VIDraft">
58
+ <img alt="VIDraft" src="https://img.shields.io/badge/VIDraft-FCD022?style=for-the-badge&logo=huggingface&logoColor=black" />
59
+ </a>
60
+ <a href="https://github.com/openfreeai">
61
+ <img src="https://img.shields.io/badge/GitHub-181717?style=for-the-badge&logo=github&logoColor=white" alt="GitHub">
62
+ </a>
63
+ <a href="https://twitter.com/openfree_ai">
64
+ <img src="https://img.shields.io/badge/Twitter-1DA1F2?style=for-the-badge&logo=twitter&logoColor=white" alt="Twitter">
65
+ </a>
66
+ <a href="https://www.linkedin.com/company/openfreeai">
67
+ <img src="https://img.shields.io/badge/LinkedIn-0077B5?style=for-the-badge&logo=linkedin&logoColor=white" alt="LinkedIn">
68
+ </a>
69
+ <a href="https://www.youtube.com/@AITechTree">
70
+ <img src="https://img.shields.io/badge/YouTube-FF0000?style=for-the-badge&logo=youtube&logoColor=white" alt="YouTube">
71
+ </a>
72
+ <a href="https://huggingface.co/openfreeai">
73
+ <img src="https://img.shields.io/badge/HuggingFace-FCC72E?style=for-the-badge&logo=huggingface&logoColor=black" alt="HuggingFace">
74
+ </a>
75
+ <a href="https://www.instagram.com/openfree_ai">
76
+ <img src="https://img.shields.io/badge/Instagram-E4405F?style=for-the-badge&logo=instagram&logoColor=white" alt="Instagram">
77
+ </a>
78
+ <a href="https://www.threads.net/@openfree_ai">
79
+ <img src="https://img.shields.io/badge/Threads-000000?style=for-the-badge&logo=threads&logoColor=white" alt="Threads">
80
+ </a>
81
+ <a href="https://www.facebook.com/profile.php?id=61575353674679">
82
+ <img src="https://img.shields.io/badge/Facebook-1877F2?style=for-the-badge&logo=facebook&logoColor=white" alt="Facebook">
83
+ </a>
84
+ </div>
85
  """)
86
 
 
87
  with gr.Row():
88
  out_code = gr.Code(label="HTML Snippet", language="html")
89
  out_preview = gr.HTML(label="Badge Preview")
90
 
 
91
  with gr.Row():
92
  label = gr.Textbox(label="Label", placeholder="예: build")
93
  message = gr.Textbox(label="Message", placeholder="예: passing")
94
  logo = gr.Textbox(label="Logo", placeholder="예: github")
95
 
 
96
  with gr.Row():
97
  color = gr.ColorPicker(label="Color", value="#a0c4ff")
98
  label_color = gr.ColorPicker(label="Label Color", value="#bdb2ff")
99
  logo_color = gr.ColorPicker(label="Logo Color", value="#ffc6ff")
100
 
 
101
  style = gr.Dropdown(label="Style", choices=["flat", "flat-square", "plastic", "for-the-badge", "social"], value="for-the-badge")
102
  link = gr.Textbox(label="Link (배지 클릭 시 이동할 URL)", placeholder="https://yourlink.com")
103
 
 
104
  inputs = [label, message, color, label_color, logo, logo_color, style, link]
105
  for inp in inputs:
106
  inp.change(fn=generate_static_badge, inputs=inputs, outputs=[out_code, out_preview])
107
 
108
+ # 실행
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  if __name__ == "__main__":
110
  demo.launch()