fantaxy commited on
Commit
79fca7e
Β·
verified Β·
1 Parent(s): 99074b7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +251 -80
app.py CHANGED
@@ -9,7 +9,6 @@ from transformers import pipeline
9
  from huggingface_hub import login
10
 
11
  # Login to Hugging Face Hub with token
12
- # You need to set the HF_TOKEN environment variable
13
  hf_token = os.getenv("HF_TOKEN")
14
  if hf_token:
15
  login(token=hf_token)
@@ -25,7 +24,7 @@ dtype = torch.bfloat16
25
  pipe = DiffusionPipeline.from_pretrained(
26
  "black-forest-labs/FLUX.1-schnell",
27
  torch_dtype=dtype,
28
- use_auth_token=hf_token # Use the token for authentication
29
  ).to(device)
30
 
31
  MAX_SEED = np.iinfo(np.int32).max
@@ -59,113 +58,285 @@ examples = [
59
  ["[ν•œκΈ€] [μŠ€νƒ€μΌ: λͺ¨λ˜] [색상: λΉ¨κ°•κ³Ό κ²€μ •] [컨셉: 식당] [ν…μŠ€νŠΈ: 'λ§›μžˆλŠ”μ§‘'] [λ°°κ²½: μ‹¬ν”Œ]"],
60
  ["[Style: Corporate] [Color: Navy and Silver] [Concept: Finance] [Text: 'TRUST'] [Background: Professional]"],
61
  ["[Style: Dynamic] [Color: Purple and Orange] [Concept: Creative Agency] [Text: 'SPARK'] [Background: Abstract]"],
62
- ["[Style: Minimalist] [Color: Red and White] [Concept: Sports] [Text: 'POWER'] [Background: Clean]"]
 
 
63
  ]
64
 
65
  css = """
66
- footer {visibility: hidden}
67
- .container {max-width: 850px; margin: auto; padding: 20px}
68
- .title {text-align: center; margin-bottom: 20px}
69
- #prompt {min-height: 50px}
70
- #result {min-height: 400px}
71
- .gr-box {border-radius: 10px; border: 1px solid #ddd}
72
- """
 
 
73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
 
75
- def create_snow_effect():
76
- # CSS μŠ€νƒ€μΌ μ •μ˜
77
- snow_css = """
78
- @keyframes snowfall {
79
- 0% {
80
- transform: translateY(-10vh) translateX(0);
81
- opacity: 1;
82
- }
83
- 100% {
84
- transform: translateY(100vh) translateX(100px);
85
- opacity: 0.3;
86
- }
87
- }
88
- .snowflake {
89
- position: fixed;
90
- color: white;
91
- font-size: 1.5em;
92
- user-select: none;
93
- z-index: 1000;
94
- pointer-events: none;
95
- animation: snowfall linear infinite;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  }
97
- """
98
-
99
- # JavaScript μ½”λ“œ μ •μ˜
100
- snow_js = """
101
- function createSnowflake() {
102
- const snowflake = document.createElement('div');
103
- snowflake.innerHTML = 'πŸ’';
104
- snowflake.className = 'snowflake';
105
- snowflake.style.left = Math.random() * 100 + 'vw';
106
- snowflake.style.animationDuration = Math.random() * 3 + 2 + 's';
107
- snowflake.style.opacity = Math.random();
108
- document.body.appendChild(snowflake);
109
-
110
- setTimeout(() => {
111
- snowflake.remove();
112
- }, 5000);
113
  }
114
- setInterval(createSnowflake, 200);
115
- """
116
-
117
- # CSS와 JavaScriptλ₯Ό κ²°ν•©ν•œ HTML
118
- snow_html = f"""
119
- <style>
120
- {snow_css}
121
- </style>
122
- <script>
123
- {snow_js}
124
- </script>
125
- """
126
-
127
- return gr.HTML(snow_html)
128
-
129
 
130
  with gr.Blocks(theme="soft", css=css) as demo:
131
- create_snow_effect()
132
- gr.HTML("<h1 class='title'>LOGO Generator AI</h1>")
 
 
 
 
 
 
133
 
134
  with gr.Column(elem_id="container"):
 
135
  with gr.Group():
136
- prompt = gr.Text(
137
- label="PROMPT",
138
- placeholder="Text input Prompt (Korean input supported)",
139
- lines=2
 
 
 
140
  )
141
- run_button = gr.Button("Generate Logo", variant="primary")
 
 
 
142
 
 
143
  with gr.Row():
144
- result = gr.Image(label="Generated Logo", show_label=True)
 
 
 
 
 
 
 
 
 
 
 
145
 
146
- with gr.Accordion("Advanced Settings", open=False):
147
- with gr.Row():
148
- seed = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=0)
149
- randomize_seed = gr.Checkbox(label="Random Seed", value=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
 
151
- with gr.Row():
152
- width = gr.Slider(label="Width", minimum=256, maximum=MAX_IMAGE_SIZE, step=32, value=512)
153
- height = gr.Slider(label="Height", minimum=256, maximum=MAX_IMAGE_SIZE, step=32, value=512)
154
- num_inference_steps = gr.Slider(label="Quality", minimum=1, maximum=50, step=1, value=4)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
155
 
 
 
156
  gr.Examples(
157
  examples=examples,
158
  fn=infer,
159
  inputs=[prompt],
160
- outputs=[result, seed],
161
  cache_examples="lazy"
162
  )
163
 
 
164
  gr.on(
165
  triggers=[run_button.click, prompt.submit],
166
  fn=infer,
167
  inputs=[prompt, seed, randomize_seed, width, height, num_inference_steps],
168
- outputs=[result, seed]
169
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
 
171
  demo.launch()
 
9
  from huggingface_hub import login
10
 
11
  # Login to Hugging Face Hub with token
 
12
  hf_token = os.getenv("HF_TOKEN")
13
  if hf_token:
14
  login(token=hf_token)
 
24
  pipe = DiffusionPipeline.from_pretrained(
25
  "black-forest-labs/FLUX.1-schnell",
26
  torch_dtype=dtype,
27
+ use_auth_token=hf_token
28
  ).to(device)
29
 
30
  MAX_SEED = np.iinfo(np.int32).max
 
58
  ["[ν•œκΈ€] [μŠ€νƒ€μΌ: λͺ¨λ˜] [색상: λΉ¨κ°•κ³Ό κ²€μ •] [컨셉: 식당] [ν…μŠ€νŠΈ: 'λ§›μžˆλŠ”μ§‘'] [λ°°κ²½: μ‹¬ν”Œ]"],
59
  ["[Style: Corporate] [Color: Navy and Silver] [Concept: Finance] [Text: 'TRUST'] [Background: Professional]"],
60
  ["[Style: Dynamic] [Color: Purple and Orange] [Concept: Creative Agency] [Text: 'SPARK'] [Background: Abstract]"],
61
+ ["[Style: Minimalist] [Color: Red and White] [Concept: Sports] [Text: 'POWER'] [Background: Clean]"],
62
+ ["[Style: Luxury] [Color: Gold and Black] [Concept: Fashion] [Text: 'ELITE'] [Background: Elegant]"],
63
+ ["[Style: Tech] [Color: Blue and Green] [Concept: AI Company] [Text: 'NEURAL'] [Background: Futuristic]"]
64
  ]
65
 
66
  css = """
67
+ /* Modern dark theme with gradients */
68
+ .container {
69
+ max-width: 1200px;
70
+ margin: auto;
71
+ padding: 30px;
72
+ background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
73
+ border-radius: 20px;
74
+ box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
75
+ }
76
 
77
+ /* Animated title with gradient */
78
+ .title {
79
+ text-align: center;
80
+ margin-bottom: 30px;
81
+ background: linear-gradient(45deg, #667eea, #764ba2, #f093fb, #f5576c);
82
+ background-size: 300% 300%;
83
+ -webkit-background-clip: text;
84
+ background-clip: text;
85
+ -webkit-text-fill-color: transparent;
86
+ animation: gradient-animation 5s ease infinite;
87
+ font-size: 3em;
88
+ font-weight: bold;
89
+ }
90
 
91
+ @keyframes gradient-animation {
92
+ 0% { background-position: 0% 50%; }
93
+ 50% { background-position: 100% 50%; }
94
+ 100% { background-position: 0% 50%; }
95
+ }
96
+
97
+ /* Enhanced input styling */
98
+ #prompt textarea {
99
+ min-height: 80px;
100
+ font-size: 16px;
101
+ background: rgba(255, 255, 255, 0.05);
102
+ border: 2px solid rgba(102, 126, 234, 0.3);
103
+ border-radius: 15px;
104
+ padding: 15px;
105
+ transition: all 0.3s ease;
106
+ }
107
+
108
+ #prompt textarea:focus {
109
+ border-color: #667eea;
110
+ box-shadow: 0 0 20px rgba(102, 126, 234, 0.5);
111
+ background: rgba(255, 255, 255, 0.08);
112
+ }
113
+
114
+ /* Enhanced button styling */
115
+ .gr-button-primary {
116
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
117
+ border: none;
118
+ padding: 15px 40px;
119
+ font-size: 18px;
120
+ font-weight: bold;
121
+ border-radius: 30px;
122
+ transition: all 0.3s ease;
123
+ box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
124
+ }
125
+
126
+ .gr-button-primary:hover {
127
+ transform: translateY(-2px);
128
+ box-shadow: 0 8px 25px rgba(102, 126, 234, 0.6);
129
+ }
130
+
131
+ /* Result image styling */
132
+ #result {
133
+ min-height: 500px;
134
+ border-radius: 20px;
135
+ overflow: hidden;
136
+ box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
137
+ background: rgba(255, 255, 255, 0.02);
138
+ margin: 20px 0;
139
+ }
140
+
141
+ /* Advanced settings styling */
142
+ .gr-accordion {
143
+ background: rgba(255, 255, 255, 0.03);
144
+ border: 1px solid rgba(255, 255, 255, 0.1);
145
+ border-radius: 15px;
146
+ margin-top: 20px;
147
+ }
148
+
149
+ /* Slider styling */
150
+ .gr-slider {
151
+ margin: 10px 0;
152
+ }
153
+
154
+ /* Example cards styling */
155
+ .gr-examples {
156
+ margin-top: 30px;
157
+ background: rgba(255, 255, 255, 0.02);
158
+ padding: 20px;
159
+ border-radius: 15px;
160
+ }
161
+
162
+ /* Info cards */
163
+ .info-card {
164
+ background: linear-gradient(135deg, rgba(102, 126, 234, 0.1), rgba(118, 75, 162, 0.1));
165
+ border: 1px solid rgba(102, 126, 234, 0.3);
166
+ border-radius: 15px;
167
+ padding: 20px;
168
+ margin: 20px 0;
169
+ }
170
+
171
+ /* Loading animation */
172
+ .generating {
173
+ animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
174
+ }
175
+
176
+ @keyframes pulse {
177
+ 0%, 100% { opacity: 1; }
178
+ 50% { opacity: 0.5; }
179
+ }
180
+
181
+ /* Footer hidden */
182
+ footer { visibility: hidden; }
183
+
184
+ /* Responsive design */
185
+ @media (max-width: 768px) {
186
+ .container {
187
+ padding: 20px;
188
  }
189
+ .title {
190
+ font-size: 2em;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
191
  }
192
+ }
193
+ """
 
 
 
 
 
 
 
 
 
 
 
 
 
194
 
195
  with gr.Blocks(theme="soft", css=css) as demo:
196
+ gr.HTML("""
197
+ <div class='container'>
198
+ <h1 class='title'>LOGO Generator AI</h1>
199
+ <p style='text-align: center; color: #a0a0a0; font-size: 1.1em; margin-bottom: 30px;'>
200
+ 🎨 Create stunning logos with AI-powered generation β€’ Supports Korean input
201
+ </p>
202
+ </div>
203
+ """)
204
 
205
  with gr.Column(elem_id="container"):
206
+ # Main input section
207
  with gr.Group():
208
+ gr.HTML("<div class='info-card'><h3>πŸ’‘ Prompt Guide</h3><p>Use structured format: [Style] [Color] [Concept] [Text] [Background]</p></div>")
209
+
210
+ prompt = gr.Textbox(
211
+ label="✨ Logo Description",
212
+ placeholder="Describe your logo design (Korean input supported)\nExample: [Style: Modern] [Color: Blue] [Concept: Tech] [Text: 'LOGO'] [Background: Clean]",
213
+ lines=3,
214
+ elem_id="prompt"
215
  )
216
+
217
+ with gr.Row():
218
+ run_button = gr.Button("πŸš€ Generate Logo", variant="primary", scale=2)
219
+ clear_button = gr.Button("πŸ—‘οΈ Clear", scale=1)
220
 
221
+ # Result section with enhanced layout
222
  with gr.Row():
223
+ with gr.Column(scale=3):
224
+ result = gr.Image(
225
+ label="Generated Logo",
226
+ show_label=True,
227
+ elem_id="result",
228
+ interactive=False
229
+ )
230
+
231
+ with gr.Column(scale=1):
232
+ gr.HTML("<div class='info-card'><h4>πŸ“Š Generation Info</h4></div>")
233
+ seed_output = gr.Number(label="Seed Used", interactive=False)
234
+ download_btn = gr.Button("πŸ“₯ Download Logo", variant="secondary")
235
 
236
+ # Advanced settings with better organization
237
+ with gr.Accordion("βš™οΈ Advanced Settings", open=False):
238
+ with gr.Tab("Generation"):
239
+ with gr.Row():
240
+ seed = gr.Slider(
241
+ label="Seed",
242
+ minimum=0,
243
+ maximum=MAX_SEED,
244
+ step=1,
245
+ value=0,
246
+ info="Set to 0 for random seed"
247
+ )
248
+ randomize_seed = gr.Checkbox(
249
+ label="Random Seed",
250
+ value=True,
251
+ info="Generate unique results each time"
252
+ )
253
+
254
+ num_inference_steps = gr.Slider(
255
+ label="Quality Steps",
256
+ minimum=1,
257
+ maximum=50,
258
+ step=1,
259
+ value=4,
260
+ info="Higher = better quality but slower"
261
+ )
262
 
263
+ with gr.Tab("Dimensions"):
264
+ with gr.Row():
265
+ width = gr.Slider(
266
+ label="Width",
267
+ minimum=256,
268
+ maximum=MAX_IMAGE_SIZE,
269
+ step=32,
270
+ value=512,
271
+ info="Logo width in pixels"
272
+ )
273
+ height = gr.Slider(
274
+ label="Height",
275
+ minimum=256,
276
+ maximum=MAX_IMAGE_SIZE,
277
+ step=32,
278
+ value=512,
279
+ info="Logo height in pixels"
280
+ )
281
+
282
+ # Preset dimensions
283
+ gr.HTML("<p style='margin-top: 10px;'>Quick presets:</p>")
284
+ with gr.Row():
285
+ square_btn = gr.Button("1:1 Square", size="sm")
286
+ wide_btn = gr.Button("16:9 Wide", size="sm")
287
+ tall_btn = gr.Button("9:16 Tall", size="sm")
288
 
289
+ # Enhanced examples section
290
+ gr.HTML("<div class='info-card'><h3>🎯 Example Prompts</h3></div>")
291
  gr.Examples(
292
  examples=examples,
293
  fn=infer,
294
  inputs=[prompt],
295
+ outputs=[result, seed_output],
296
  cache_examples="lazy"
297
  )
298
 
299
+ # Event handlers
300
  gr.on(
301
  triggers=[run_button.click, prompt.submit],
302
  fn=infer,
303
  inputs=[prompt, seed, randomize_seed, width, height, num_inference_steps],
304
+ outputs=[result, seed_output]
305
  )
306
+
307
+ # Clear button functionality
308
+ clear_button.click(
309
+ fn=lambda: (None, None),
310
+ outputs=[prompt, result]
311
+ )
312
+
313
+ # Preset dimension buttons
314
+ square_btn.click(
315
+ fn=lambda: (512, 512),
316
+ outputs=[width, height]
317
+ )
318
+
319
+ wide_btn.click(
320
+ fn=lambda: (1024, 576),
321
+ outputs=[width, height]
322
+ )
323
+
324
+ tall_btn.click(
325
+ fn=lambda: (576, 1024),
326
+ outputs=[width, height]
327
+ )
328
+
329
+ # Tips section
330
+ gr.HTML("""
331
+ <div class='info-card' style='margin-top: 30px;'>
332
+ <h3>πŸ’‘ Pro Tips</h3>
333
+ <ul style='color: #a0a0a0;'>
334
+ <li>Use structured prompts for better results</li>
335
+ <li>Korean prompts are automatically translated</li>
336
+ <li>Higher quality steps = better detail but slower generation</li>
337
+ <li>Experiment with different seeds for variations</li>
338
+ </ul>
339
+ </div>
340
+ """)
341
 
342
  demo.launch()