Update app.py
Browse files
app.py
CHANGED
|
@@ -32,7 +32,7 @@ def process_images(annotated_image, second_image, user_api_key=None, progress=gr
|
|
| 32 |
|
| 33 |
# Construct the dynamic prompt with the actual box coordinates
|
| 34 |
prompt = f"""add the <central object in the second image> in the first image only inside an imaginary box defined by pixels values "xmin": {xmin}, "ymin": {ymin}, "xmax": {xmax}, "ymax": {ymax}. Take care of shadows, lighting, style, and general concept of objects as per the first image."""
|
| 35 |
-
|
| 36 |
progress(0.2, desc="Gradio is preparing your images...")
|
| 37 |
|
| 38 |
try:
|
|
@@ -146,8 +146,7 @@ def process_images(annotated_image, second_image, user_api_key=None, progress=gr
|
|
| 146 |
else:
|
| 147 |
os.environ.pop("FAL_KEY", None)
|
| 148 |
|
| 149 |
-
|
| 150 |
-
example_image_banner = gr.HTML(
|
| 151 |
"""
|
| 152 |
<style>
|
| 153 |
.animation-container {
|
|
@@ -521,14 +520,14 @@ example_image_banner = gr.HTML(
|
|
| 521 |
</style>
|
| 522 |
|
| 523 |
<div class="animation-container">
|
| 524 |
-
<div class="animation-title">
|
| 525 |
<div class="mini-container" id="animContainer">
|
| 526 |
<!-- Set 1 Images -->
|
| 527 |
<div class="mini-image-wrapper mini-left-image set1" style="animation-play-state: running;">
|
| 528 |
-
<img src="/gradio_api/file
|
| 529 |
</div>
|
| 530 |
<div class="mini-image-wrapper mini-right-image set1" style="animation-play-state: running;">
|
| 531 |
-
<img src="/gradio_api/file
|
| 532 |
</div>
|
| 533 |
<div class="mini-result-image set1" style="animation-play-state: running;">
|
| 534 |
<img src="/gradio_api/file=one-3.jpg" alt="Set1 Result">
|
|
@@ -536,10 +535,10 @@ example_image_banner = gr.HTML(
|
|
| 536 |
|
| 537 |
<!-- Set 2 Images -->
|
| 538 |
<div class="mini-image-wrapper mini-left-image set2" style="animation-play-state: running;">
|
| 539 |
-
<img src="/gradio_api/file
|
| 540 |
</div>
|
| 541 |
<div class="mini-image-wrapper mini-right-image set2" style="animation-play-state: running;">
|
| 542 |
-
<img src="/gradio_api/file
|
| 543 |
</div>
|
| 544 |
<div class="mini-result-image set2" style="animation-play-state: running;">
|
| 545 |
<img src="/gradio_api/file=two-3.jpeg" alt="Set2 Result">
|
|
@@ -547,13 +546,13 @@ example_image_banner = gr.HTML(
|
|
| 547 |
|
| 548 |
<!-- Set 3 Images -->
|
| 549 |
<div class="mini-image-wrapper mini-left-image set3" style="animation-play-state: running;">
|
| 550 |
-
<img src="/gradio_api/file
|
| 551 |
</div>
|
| 552 |
<div class="mini-image-wrapper mini-right-image set3" style="animation-play-state: running;">
|
| 553 |
-
<img src="/gradio_api/file
|
| 554 |
</div>
|
| 555 |
<div class="mini-result-image set3" style="animation-play-state: running;">
|
| 556 |
-
<img src="/gradio_api/file
|
| 557 |
</div>
|
| 558 |
|
| 559 |
<!-- Progress bar -->
|
|
@@ -580,33 +579,35 @@ with gr.Blocks(theme='ocean') as demo:
|
|
| 580 |
# Add navigation bar
|
| 581 |
navbar = gr.Navbar(
|
| 582 |
value=[
|
| 583 |
-
("
|
| 584 |
("FAL.AI nano-banana", "https://fal.ai/models/fal-ai/nano-banana/edit/api"),
|
| 585 |
-
|
|
|
|
| 586 |
visible=True,
|
| 587 |
main_page_name="🎨 guided nano banana"
|
| 588 |
)
|
|
|
|
|
|
|
|
|
|
| 589 |
|
| 590 |
-
|
| 591 |
-
|
| 592 |
-
|
| 593 |
-
|
| 594 |
-
"""
|
| 595 |
-
<h1><center>Guide Your Nano Banana👉🍌</center></h1>
|
| 596 |
|
| 597 |
-
|
| 598 |
-
|
| 599 |
-
|
| 600 |
-
|
| 601 |
|
| 602 |
-
|
| 603 |
-
|
| 604 |
-
|
| 605 |
-
|
| 606 |
|
| 607 |
# API Key input section
|
| 608 |
-
with gr.Row():
|
| 609 |
-
with gr.Column():
|
| 610 |
with gr.Accordion("🔑 API Configuration (Optional)", open=False):
|
| 611 |
gr.Markdown(
|
| 612 |
"""
|
|
@@ -682,24 +683,24 @@ with gr.Blocks(theme='ocean') as demo:
|
|
| 682 |
examples = [
|
| 683 |
[
|
| 684 |
{
|
| 685 |
-
"image": "
|
| 686 |
"boxes": [{"xmin": 61, "ymin": 298, "xmax": 228, "ymax": 462}],
|
| 687 |
},
|
| 688 |
-
"
|
| 689 |
],
|
| 690 |
[
|
| 691 |
{
|
| 692 |
-
"image": "
|
| 693 |
"boxes": [{"xmin": 205, "ymin": 791, "xmax": 813, "ymax": 1161}],
|
| 694 |
},
|
| 695 |
-
"
|
| 696 |
],
|
| 697 |
[
|
| 698 |
{
|
| 699 |
-
"image": "
|
| 700 |
"boxes": [{"xmin": 24, "ymin": 465, "xmax": 146, "ymax": 607}],
|
| 701 |
},
|
| 702 |
-
"
|
| 703 |
],
|
| 704 |
]
|
| 705 |
|
|
@@ -708,14 +709,15 @@ with gr.Blocks(theme='ocean') as demo:
|
|
| 708 |
inputs=[first_image, second_image],
|
| 709 |
)
|
| 710 |
|
| 711 |
-
|
|
|
|
| 712 |
gr.Markdown(
|
| 713 |
"""
|
| 714 |
# ℹ️ Tips for Best Results
|
| 715 |
- **Box Placement**: Draw the box exactly where you want the object to appear
|
| 716 |
- **Image Quality**: Use high-resolution images for better results
|
| 717 |
- **Object Selection**: The second image should clearly show the object you want to insert
|
| 718 |
-
|
| 719 |
- **Processing Time**: Generation typically takes 10-30 seconds
|
| 720 |
- **API Key**: If you encounter errors, try using your own FAL API key
|
| 721 |
"""
|
|
@@ -728,4 +730,4 @@ with demo.route("ℹ️Tips for Best Results", "/tips"):
|
|
| 728 |
)
|
| 729 |
|
| 730 |
if __name__ == "__main__":
|
| 731 |
-
demo.launch(ssr_mode=False, allowed_paths=["."])
|
|
|
|
| 32 |
|
| 33 |
# Construct the dynamic prompt with the actual box coordinates
|
| 34 |
prompt = f"""add the <central object in the second image> in the first image only inside an imaginary box defined by pixels values "xmin": {xmin}, "ymin": {ymin}, "xmax": {xmax}, "ymax": {ymax}. Take care of shadows, lighting, style, and general concept of objects as per the first image."""
|
| 35 |
+
print(f"prompt - {prompt}")
|
| 36 |
progress(0.2, desc="Gradio is preparing your images...")
|
| 37 |
|
| 38 |
try:
|
|
|
|
| 146 |
else:
|
| 147 |
os.environ.pop("FAL_KEY", None)
|
| 148 |
|
| 149 |
+
examples_image_banner=gr.HTML(
|
|
|
|
| 150 |
"""
|
| 151 |
<style>
|
| 152 |
.animation-container {
|
|
|
|
| 520 |
</style>
|
| 521 |
|
| 522 |
<div class="animation-container">
|
| 523 |
+
<div class="animation-title">Image Fusion Magic ✨</div>
|
| 524 |
<div class="mini-container" id="animContainer">
|
| 525 |
<!-- Set 1 Images -->
|
| 526 |
<div class="mini-image-wrapper mini-left-image set1" style="animation-play-state: running;">
|
| 527 |
+
<img src="/gradio_api/file=/content/one-1.png" alt="Set1 Left"> <!--src would be file/my_image.png*/ -->
|
| 528 |
</div>
|
| 529 |
<div class="mini-image-wrapper mini-right-image set1" style="animation-play-state: running;">
|
| 530 |
+
<img src="/gradio_api/file=/content/one-2.png" alt="Set1 Right">
|
| 531 |
</div>
|
| 532 |
<div class="mini-result-image set1" style="animation-play-state: running;">
|
| 533 |
<img src="/gradio_api/file=one-3.jpg" alt="Set1 Result">
|
|
|
|
| 535 |
|
| 536 |
<!-- Set 2 Images -->
|
| 537 |
<div class="mini-image-wrapper mini-left-image set2" style="animation-play-state: running;">
|
| 538 |
+
<img src="/gradio_api/file=/content/two-1.png" alt="Set2 Left">
|
| 539 |
</div>
|
| 540 |
<div class="mini-image-wrapper mini-right-image set2" style="animation-play-state: running;">
|
| 541 |
+
<img src="/gradio_api/file=/content/two-2.png" alt="Set2 Right">
|
| 542 |
</div>
|
| 543 |
<div class="mini-result-image set2" style="animation-play-state: running;">
|
| 544 |
<img src="/gradio_api/file=two-3.jpeg" alt="Set2 Result">
|
|
|
|
| 546 |
|
| 547 |
<!-- Set 3 Images -->
|
| 548 |
<div class="mini-image-wrapper mini-left-image set3" style="animation-play-state: running;">
|
| 549 |
+
<img src="/gradio_api/file=/content/three-1.png" alt="Set3 Left">
|
| 550 |
</div>
|
| 551 |
<div class="mini-image-wrapper mini-right-image set3" style="animation-play-state: running;">
|
| 552 |
+
<img src="/gradio_api/file=/content/three-2.png" alt="Set3 Right">
|
| 553 |
</div>
|
| 554 |
<div class="mini-result-image set3" style="animation-play-state: running;">
|
| 555 |
+
<img src="/gradio_api/file=/content/three-3.jpg" alt="Set3 Result">
|
| 556 |
</div>
|
| 557 |
|
| 558 |
<!-- Progress bar -->
|
|
|
|
| 579 |
# Add navigation bar
|
| 580 |
navbar = gr.Navbar(
|
| 581 |
value=[
|
| 582 |
+
("Documentation", "https://docs.fal.ai"),
|
| 583 |
("FAL.AI nano-banana", "https://fal.ai/models/fal-ai/nano-banana/edit/api"),
|
| 584 |
+
("Learn more about Gradio Navbar", "https://www.gradio.app/guides/multipage-apps#customizing-the-navbar")
|
| 585 |
+
],
|
| 586 |
visible=True,
|
| 587 |
main_page_name="🎨 guided nano banana"
|
| 588 |
)
|
| 589 |
+
with gr.Row():
|
| 590 |
+
# Add the animated banner
|
| 591 |
+
examples_image_banner.render()
|
| 592 |
|
| 593 |
+
with gr.Column():
|
| 594 |
+
gr.HTML(
|
| 595 |
+
"""
|
| 596 |
+
<h1><center>Guide Your Nano Banana👉🍌</center></h1>
|
|
|
|
|
|
|
| 597 |
|
| 598 |
+
<b>How to use:</b><br>
|
| 599 |
+
1. Upload or capture the first image and draw a box where you want to place an object<br>
|
| 600 |
+
2. Upload the second image containing the object you want to insert<br>
|
| 601 |
+
3. Click "Generate Composite Image" and wait for the Gradio and Nano-Banana to blend the images<br>
|
| 602 |
|
| 603 |
+
The Gradio app will intelligently place the object from the second image into the boxed area of the first image,
|
| 604 |
+
taking care of lighting, shadows, and proper integration.
|
| 605 |
+
"""
|
| 606 |
+
)
|
| 607 |
|
| 608 |
# API Key input section
|
| 609 |
+
#with gr.Row():
|
| 610 |
+
#with gr.Column():
|
| 611 |
with gr.Accordion("🔑 API Configuration (Optional)", open=False):
|
| 612 |
gr.Markdown(
|
| 613 |
"""
|
|
|
|
| 683 |
examples = [
|
| 684 |
[
|
| 685 |
{
|
| 686 |
+
"image": "example1-1.png",
|
| 687 |
"boxes": [{"xmin": 61, "ymin": 298, "xmax": 228, "ymax": 462}],
|
| 688 |
},
|
| 689 |
+
"example1-2.png",
|
| 690 |
],
|
| 691 |
[
|
| 692 |
{
|
| 693 |
+
"image": "example2-1.png",
|
| 694 |
"boxes": [{"xmin": 205, "ymin": 791, "xmax": 813, "ymax": 1161}],
|
| 695 |
},
|
| 696 |
+
"example2-2.jpg",
|
| 697 |
],
|
| 698 |
[
|
| 699 |
{
|
| 700 |
+
"image": "example3-1.png",
|
| 701 |
"boxes": [{"xmin": 24, "ymin": 465, "xmax": 146, "ymax": 607}],
|
| 702 |
},
|
| 703 |
+
"example3-2.png",
|
| 704 |
],
|
| 705 |
]
|
| 706 |
|
|
|
|
| 709 |
inputs=[first_image, second_image],
|
| 710 |
)
|
| 711 |
|
| 712 |
+
|
| 713 |
+
with demo.route("Tips", "/tips"):
|
| 714 |
gr.Markdown(
|
| 715 |
"""
|
| 716 |
# ℹ️ Tips for Best Results
|
| 717 |
- **Box Placement**: Draw the box exactly where you want the object to appear
|
| 718 |
- **Image Quality**: Use high-resolution images for better results
|
| 719 |
- **Object Selection**: The second image should clearly show the object you want to insert
|
| 720 |
+
- **Lighting**: Images with similar lighting conditions work best
|
| 721 |
- **Processing Time**: Generation typically takes 10-30 seconds
|
| 722 |
- **API Key**: If you encounter errors, try using your own FAL API key
|
| 723 |
"""
|
|
|
|
| 730 |
)
|
| 731 |
|
| 732 |
if __name__ == "__main__":
|
| 733 |
+
demo.launch(ssr_mode=False, allowed_paths=["."], debug=False)
|