Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
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
|
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 |
-
|
67 |
-
.container {
|
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 |
-
# 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 |
-
|
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 |
-
|
132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
|
134 |
with gr.Column(elem_id="container"):
|
|
|
135 |
with gr.Group():
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
|
|
|
|
|
|
140 |
)
|
141 |
-
|
|
|
|
|
|
|
142 |
|
|
|
143 |
with gr.Row():
|
144 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
|
151 |
-
with gr.
|
152 |
-
|
153 |
-
|
154 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
155 |
|
|
|
|
|
156 |
gr.Examples(
|
157 |
examples=examples,
|
158 |
fn=infer,
|
159 |
inputs=[prompt],
|
160 |
-
outputs=[result,
|
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,
|
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()
|