Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -313,72 +313,135 @@ def generate_image(
|
|
| 313 |
|
| 314 |
return images[0], gr.update(visible=True)
|
| 315 |
|
| 316 |
-
#
|
| 317 |
title = r"""
|
| 318 |
-
<h1 align="center">🎯 Pro AI Headshot Generator</h1>
|
| 319 |
"""
|
| 320 |
|
| 321 |
description = r"""
|
| 322 |
-
<
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
1. <b>Upload</b> a clear photo of your face<br>
|
| 327 |
-
2. <b>Choose</b> your preferred style<br>
|
| 328 |
-
3. <b>Click Generate</b> and download your professional headshots<br><br>
|
| 329 |
-
|
| 330 |
-
<em>No technical knowledge needed - we handle all the complex AI settings automatically!</em>
|
| 331 |
"""
|
| 332 |
|
| 333 |
css = """
|
| 334 |
-
.gradio-container {
|
| 335 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 336 |
"""
|
| 337 |
|
| 338 |
-
with gr.Blocks(css=css) as demo:
|
| 339 |
gr.Markdown(title)
|
| 340 |
gr.Markdown(description)
|
| 341 |
|
| 342 |
with gr.Row():
|
| 343 |
with gr.Column(scale=1):
|
| 344 |
-
# Instructions
|
| 345 |
with gr.Group():
|
| 346 |
gr.Markdown("""
|
| 347 |
-
<div class="instructions">
|
| 348 |
-
<h3
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
|
|
|
|
|
|
| 353 |
</div>
|
| 354 |
""")
|
| 355 |
|
| 356 |
-
#
|
| 357 |
with gr.Group():
|
| 358 |
-
gr.Markdown("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 359 |
face_file = gr.Image(
|
| 360 |
-
label="
|
| 361 |
type="filepath",
|
| 362 |
-
height=200
|
|
|
|
| 363 |
)
|
| 364 |
-
|
| 365 |
-
# Style Selection
|
| 366 |
with gr.Group():
|
| 367 |
-
gr.Markdown("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 368 |
style = gr.Dropdown(
|
| 369 |
label="Professional Style",
|
| 370 |
-
choices=STYLE_NAMES,
|
| 371 |
-
value=
|
| 372 |
-
info="
|
| 373 |
)
|
| 374 |
-
|
| 375 |
-
#
|
| 376 |
with gr.Accordion("⚙️ Advanced Settings (Optional)", open=False):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 377 |
prompt = gr.Textbox(
|
| 378 |
label="Custom Description",
|
| 379 |
-
placeholder="
|
| 380 |
-
value="professional headshot",
|
| 381 |
-
info="
|
| 382 |
)
|
| 383 |
|
| 384 |
with gr.Row():
|
|
@@ -388,38 +451,56 @@ with gr.Blocks(css=css) as demo:
|
|
| 388 |
maximum=1.2,
|
| 389 |
step=0.05,
|
| 390 |
value=0.80,
|
|
|
|
| 391 |
)
|
| 392 |
adapter_strength_ratio = gr.Slider(
|
| 393 |
label="Detail Quality",
|
| 394 |
-
minimum=0.
|
| 395 |
maximum=1.2,
|
| 396 |
step=0.05,
|
| 397 |
-
value=0.
|
|
|
|
| 398 |
)
|
| 399 |
|
| 400 |
enable_LCM = gr.Checkbox(
|
| 401 |
-
label="Fast Generation Mode",
|
| 402 |
value=False,
|
| 403 |
-
info="
|
| 404 |
)
|
| 405 |
|
| 406 |
# Generate Button
|
| 407 |
-
submit = gr.Button(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 408 |
|
| 409 |
with gr.Column(scale=1):
|
| 410 |
# Results Section
|
| 411 |
-
gr.Markdown("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 412 |
gallery = gr.Image(
|
| 413 |
-
label="
|
| 414 |
-
height=
|
| 415 |
-
show_download_button=True
|
|
|
|
| 416 |
)
|
| 417 |
|
| 418 |
# Success Message
|
| 419 |
success_msg = gr.Markdown("""
|
| 420 |
-
<div
|
| 421 |
-
<
|
| 422 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 423 |
</div>
|
| 424 |
""", visible=False)
|
| 425 |
|
|
@@ -441,8 +522,17 @@ with gr.Blocks(css=css) as demo:
|
|
| 441 |
def show_success():
|
| 442 |
return gr.update(visible=True)
|
| 443 |
|
| 444 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 445 |
submit.click(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 446 |
fn=generate_image,
|
| 447 |
inputs=[
|
| 448 |
face_file,
|
|
|
|
| 313 |
|
| 314 |
return images[0], gr.update(visible=True)
|
| 315 |
|
| 316 |
+
# MODERN ATTRACTIVE UI
|
| 317 |
title = r"""
|
| 318 |
+
<h1 align="center" style="color: #2563eb; font-size: 2.5em; margin-bottom: 0.2em;">🎯 Pro AI Headshot Generator</h1>
|
| 319 |
"""
|
| 320 |
|
| 321 |
description = r"""
|
| 322 |
+
<div style="text-align: center; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); padding: 25px; border-radius: 15px; color: white; margin-bottom: 25px;">
|
| 323 |
+
<h2 style="margin: 0; font-size: 1.5em;">✨ Transform Any Selfie Into Professional Headshots</h2>
|
| 324 |
+
<p style="margin: 10px 0 0 0; font-size: 1.1em;">Perfect for LinkedIn, Corporate Profiles & Professional Portfolios</p>
|
| 325 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 326 |
"""
|
| 327 |
|
| 328 |
css = """
|
| 329 |
+
.gradio-container {
|
| 330 |
+
max-width: 1200px !important;
|
| 331 |
+
font-family: 'Inter', sans-serif;
|
| 332 |
+
}
|
| 333 |
+
.welcome-box {
|
| 334 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 335 |
+
padding: 25px;
|
| 336 |
+
border-radius: 15px;
|
| 337 |
+
color: white;
|
| 338 |
+
margin-bottom: 25px;
|
| 339 |
+
text-align: center;
|
| 340 |
+
}
|
| 341 |
+
.instructions-box {
|
| 342 |
+
background: #f8fafc;
|
| 343 |
+
padding: 20px;
|
| 344 |
+
border-radius: 12px;
|
| 345 |
+
border-left: 4px solid #3b82f6;
|
| 346 |
+
margin-bottom: 20px;
|
| 347 |
+
}
|
| 348 |
+
.upload-section {
|
| 349 |
+
background: white;
|
| 350 |
+
padding: 20px;
|
| 351 |
+
border-radius: 12px;
|
| 352 |
+
border: 2px dashed #d1d5db;
|
| 353 |
+
margin-bottom: 20px;
|
| 354 |
+
}
|
| 355 |
+
.results-section {
|
| 356 |
+
background: white;
|
| 357 |
+
padding: 25px;
|
| 358 |
+
border-radius: 12px;
|
| 359 |
+
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
|
| 360 |
+
border: 1px solid #e5e7eb;
|
| 361 |
+
}
|
| 362 |
+
.success-message {
|
| 363 |
+
background: #dcfce7;
|
| 364 |
+
padding: 20px;
|
| 365 |
+
border-radius: 12px;
|
| 366 |
+
border-left: 4px solid #22c55e;
|
| 367 |
+
margin-top: 20px;
|
| 368 |
+
}
|
| 369 |
+
.advanced-settings {
|
| 370 |
+
background: #fef3c7;
|
| 371 |
+
padding: 15px;
|
| 372 |
+
border-radius: 10px;
|
| 373 |
+
border: 1px solid #f59e0b;
|
| 374 |
+
}
|
| 375 |
"""
|
| 376 |
|
| 377 |
+
with gr.Blocks(css=css, theme=gr.themes.Soft()) as demo:
|
| 378 |
gr.Markdown(title)
|
| 379 |
gr.Markdown(description)
|
| 380 |
|
| 381 |
with gr.Row():
|
| 382 |
with gr.Column(scale=1):
|
| 383 |
+
# Welcome & Instructions
|
| 384 |
with gr.Group():
|
| 385 |
gr.Markdown("""
|
| 386 |
+
<div class="instructions-box">
|
| 387 |
+
<h3>🎯 How to Create Perfect Headshots</h3>
|
| 388 |
+
<p><strong>Follow these 3 simple steps:</strong></p>
|
| 389 |
+
<ol>
|
| 390 |
+
<li><strong>Upload</strong> a clear photo of your face</li>
|
| 391 |
+
<li><strong>Choose</strong> your preferred style (optional)</li>
|
| 392 |
+
<li><strong>Generate</strong> and download your professional headshots</li>
|
| 393 |
+
</ol>
|
| 394 |
</div>
|
| 395 |
""")
|
| 396 |
|
| 397 |
+
# Upload Section
|
| 398 |
with gr.Group():
|
| 399 |
+
gr.Markdown("""
|
| 400 |
+
<div class="upload-section">
|
| 401 |
+
<h3>📸 Step 1: Upload Your Photo</h3>
|
| 402 |
+
<p><em>For best results, use a clear, well-lit photo where your face is clearly visible</em></p>
|
| 403 |
+
</div>
|
| 404 |
+
""")
|
| 405 |
face_file = gr.Image(
|
| 406 |
+
label="",
|
| 407 |
type="filepath",
|
| 408 |
+
height=200,
|
| 409 |
+
show_label=False
|
| 410 |
)
|
| 411 |
+
|
| 412 |
+
# Style Selection
|
| 413 |
with gr.Group():
|
| 414 |
+
gr.Markdown("""
|
| 415 |
+
<div style="padding: 15px; background: white; border-radius: 10px; margin-bottom: 15px;">
|
| 416 |
+
<h3>🎨 Step 2: Choose Your Style (Optional)</h3>
|
| 417 |
+
<p><em>Select a style that matches your professional needs. Leave as "No Style" for natural results.</em></p>
|
| 418 |
+
</div>
|
| 419 |
+
""")
|
| 420 |
style = gr.Dropdown(
|
| 421 |
label="Professional Style",
|
| 422 |
+
choices=["No Style"] + STYLE_NAMES,
|
| 423 |
+
value="No Style",
|
| 424 |
+
info="Choose a style or keep 'No Style' for natural professional results"
|
| 425 |
)
|
| 426 |
+
|
| 427 |
+
# Advanced Settings
|
| 428 |
with gr.Accordion("⚙️ Advanced Settings (Optional)", open=False):
|
| 429 |
+
gr.Markdown("""
|
| 430 |
+
<div class="advanced-settings">
|
| 431 |
+
<p><strong>💡 Pro Tips:</strong></p>
|
| 432 |
+
<ul>
|
| 433 |
+
<li><strong>Face Similarity:</strong> Higher = More like your photo (0.8 is perfect)</li>
|
| 434 |
+
<li><strong>Detail Quality:</strong> Higher = More detailed but may change appearance (0.55 is optimal)</li>
|
| 435 |
+
<li><strong>Custom Description:</strong> Describe how you want to appear</li>
|
| 436 |
+
</ul>
|
| 437 |
+
</div>
|
| 438 |
+
""")
|
| 439 |
+
|
| 440 |
prompt = gr.Textbox(
|
| 441 |
label="Custom Description",
|
| 442 |
+
placeholder="Describe your desired look...",
|
| 443 |
+
value="modern professional headshot, creative director style, soft natural lighting, authentic expression, contemporary business portrait, premium quality photo, professional yet approachable, magazine-style portrait, high-end photography",
|
| 444 |
+
info="This describes how you'll appear in the headshot"
|
| 445 |
)
|
| 446 |
|
| 447 |
with gr.Row():
|
|
|
|
| 451 |
maximum=1.2,
|
| 452 |
step=0.05,
|
| 453 |
value=0.80,
|
| 454 |
+
info="How closely the headshot should resemble your face"
|
| 455 |
)
|
| 456 |
adapter_strength_ratio = gr.Slider(
|
| 457 |
label="Detail Quality",
|
| 458 |
+
minimum=0.3,
|
| 459 |
maximum=1.2,
|
| 460 |
step=0.05,
|
| 461 |
+
value=0.55,
|
| 462 |
+
info="Level of detail and quality in the final image"
|
| 463 |
)
|
| 464 |
|
| 465 |
enable_LCM = gr.Checkbox(
|
| 466 |
+
label="🚀 Fast Generation Mode",
|
| 467 |
value=False,
|
| 468 |
+
info="Generate faster with slightly lower quality (good for testing)"
|
| 469 |
)
|
| 470 |
|
| 471 |
# Generate Button
|
| 472 |
+
submit = gr.Button(
|
| 473 |
+
"✨ Generate Professional Headshots",
|
| 474 |
+
variant="primary",
|
| 475 |
+
size="lg",
|
| 476 |
+
elem_id="generate-btn"
|
| 477 |
+
)
|
| 478 |
|
| 479 |
with gr.Column(scale=1):
|
| 480 |
# Results Section
|
| 481 |
+
gr.Markdown("""
|
| 482 |
+
<div class="results-section">
|
| 483 |
+
<h2>🎉 Your Professional Headshots</h2>
|
| 484 |
+
<p><em>Your generated headshot will appear here. Click the download button to save your professional image.</em></p>
|
| 485 |
+
</div>
|
| 486 |
+
""")
|
| 487 |
gallery = gr.Image(
|
| 488 |
+
label="",
|
| 489 |
+
height=450,
|
| 490 |
+
show_download_button=True,
|
| 491 |
+
show_label=False
|
| 492 |
)
|
| 493 |
|
| 494 |
# Success Message
|
| 495 |
success_msg = gr.Markdown("""
|
| 496 |
+
<div class="success-message">
|
| 497 |
+
<h3>✅ Success! Your Professional Headshot is Ready</h3>
|
| 498 |
+
<p><strong>Next Steps:</strong></p>
|
| 499 |
+
<ul>
|
| 500 |
+
<li>Click the download button above to save your headshot</li>
|
| 501 |
+
<li>Use it for LinkedIn, professional profiles, or portfolios</li>
|
| 502 |
+
<li>Need a different style? Adjust settings and generate again!</li>
|
| 503 |
+
</ul>
|
| 504 |
</div>
|
| 505 |
""", visible=False)
|
| 506 |
|
|
|
|
| 522 |
def show_success():
|
| 523 |
return gr.update(visible=True)
|
| 524 |
|
| 525 |
+
def apply_no_style(style_name, current_prompt):
|
| 526 |
+
if style_name == "No Style":
|
| 527 |
+
return current_prompt
|
| 528 |
+
return current_prompt
|
| 529 |
+
|
| 530 |
submit.click(
|
| 531 |
+
fn=apply_no_style,
|
| 532 |
+
inputs=[style, prompt],
|
| 533 |
+
outputs=prompt,
|
| 534 |
+
queue=False
|
| 535 |
+
).then(
|
| 536 |
fn=generate_image,
|
| 537 |
inputs=[
|
| 538 |
face_file,
|