with Download Buttons
Browse files
app.py
CHANGED
|
@@ -4,7 +4,9 @@ import numpy as np
|
|
| 4 |
import random
|
| 5 |
import os
|
| 6 |
import sys
|
|
|
|
| 7 |
|
|
|
|
| 8 |
from diffusers.utils import load_image
|
| 9 |
from diffusers import EulerDiscreteScheduler, T2IAdapter
|
| 10 |
|
|
@@ -174,7 +176,17 @@ def generate_image(
|
|
| 174 |
adapter_conditioning_scale=adapter_conditioning_scale,
|
| 175 |
adapter_conditioning_factor=adapter_conditioning_factor,
|
| 176 |
).images
|
| 177 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
|
| 179 |
def swap_to_gallery(images):
|
| 180 |
return gr.update(value=images, visible=True), gr.update(visible=True), gr.update(visible=False)
|
|
@@ -391,6 +403,14 @@ background: linear-gradient(135deg, #CCFED9, #95BAFF);
|
|
| 391 |
background: #553566 !important;
|
| 392 |
color: white !important;
|
| 393 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 394 |
html body h1#app-title {
|
| 395 |
text-align: center;
|
| 396 |
font-size: 40px;
|
|
@@ -471,7 +491,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 471 |
label="Drag (Select) 1 or more photos of your face",
|
| 472 |
file_types=["image"]
|
| 473 |
)
|
| 474 |
-
uploaded_files = gr.Gallery(label="Your images", visible=False, columns=5, rows=1, height=200)
|
| 475 |
with gr.Column(visible=False, elem_id="reupload_wrapper") as clear_button:
|
| 476 |
remove_and_reupload = gr.ClearButton(value="Remove and upload new ones", components=files, size="sm")
|
| 477 |
|
|
@@ -593,7 +613,11 @@ with gr.Blocks(css=css) as demo:
|
|
| 593 |
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
| 594 |
with gr.Column():
|
| 595 |
# gallery = gr.Gallery(label="Generated Images")
|
| 596 |
-
gallery = gr.Gallery(label="Generated Images", show_share_button=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 597 |
usage_tips = gr.Markdown(label="Usage tips of PhotoMaker", value=tips ,visible=False, elem_id="usage_tips_section")
|
| 598 |
|
| 599 |
# usage_tips = gr.Markdown(label="Usage tips of PhotoMaker", value=tips ,visible=False)
|
|
@@ -631,7 +655,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 631 |
).then(
|
| 632 |
fn=generate_image,
|
| 633 |
inputs=input_list,
|
| 634 |
-
outputs=[gallery, usage_tips]
|
| 635 |
)
|
| 636 |
|
| 637 |
# When user clicks on a suggestion, fill the prompt textbox and close popup
|
|
|
|
| 4 |
import random
|
| 5 |
import os
|
| 6 |
import sys
|
| 7 |
+
import tempfile
|
| 8 |
|
| 9 |
+
from PIL import Image
|
| 10 |
from diffusers.utils import load_image
|
| 11 |
from diffusers import EulerDiscreteScheduler, T2IAdapter
|
| 12 |
|
|
|
|
| 176 |
adapter_conditioning_scale=adapter_conditioning_scale,
|
| 177 |
adapter_conditioning_factor=adapter_conditioning_factor,
|
| 178 |
).images
|
| 179 |
+
|
| 180 |
+
# Save images to temp files for download
|
| 181 |
+
temp_paths = []
|
| 182 |
+
for i, img in enumerate(images):
|
| 183 |
+
tmp = tempfile.NamedTemporaryFile(delete=False, suffix=".png")
|
| 184 |
+
img.save(tmp.name)
|
| 185 |
+
temp_paths.append(tmp.name)
|
| 186 |
+
|
| 187 |
+
return images, gr.update(visible=True), temp_paths[0], temp_paths[1]
|
| 188 |
+
|
| 189 |
+
# return images, gr.update(visible=True)
|
| 190 |
|
| 191 |
def swap_to_gallery(images):
|
| 192 |
return gr.update(value=images, visible=True), gr.update(visible=True), gr.update(visible=False)
|
|
|
|
| 403 |
background: #553566 !important;
|
| 404 |
color: white !important;
|
| 405 |
}
|
| 406 |
+
#download_btn1 {
|
| 407 |
+
background: #553566 !important;
|
| 408 |
+
color: white !important;
|
| 409 |
+
}
|
| 410 |
+
#download_btn2 {
|
| 411 |
+
background: #553566 !important;
|
| 412 |
+
color: white !important;
|
| 413 |
+
}
|
| 414 |
html body h1#app-title {
|
| 415 |
text-align: center;
|
| 416 |
font-size: 40px;
|
|
|
|
| 491 |
label="Drag (Select) 1 or more photos of your face",
|
| 492 |
file_types=["image"]
|
| 493 |
)
|
| 494 |
+
uploaded_files = gr.Gallery(label="Your images", visible=False, columns=5, rows=1, height=200, show_share_button=False, show_download_button=False)
|
| 495 |
with gr.Column(visible=False, elem_id="reupload_wrapper") as clear_button:
|
| 496 |
remove_and_reupload = gr.ClearButton(value="Remove and upload new ones", components=files, size="sm")
|
| 497 |
|
|
|
|
| 613 |
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
| 614 |
with gr.Column():
|
| 615 |
# gallery = gr.Gallery(label="Generated Images")
|
| 616 |
+
gallery = gr.Gallery(label="Generated Images", show_share_button=False, show_download_button=False)
|
| 617 |
+
download_btn1 = gr.DownloadButton(label="Download Image 1", elem_id="download_btn1")
|
| 618 |
+
download_btn2 = gr.DownloadButton(label="Download Image 2", elem_id="download_btn2")
|
| 619 |
+
|
| 620 |
+
|
| 621 |
usage_tips = gr.Markdown(label="Usage tips of PhotoMaker", value=tips ,visible=False, elem_id="usage_tips_section")
|
| 622 |
|
| 623 |
# usage_tips = gr.Markdown(label="Usage tips of PhotoMaker", value=tips ,visible=False)
|
|
|
|
| 655 |
).then(
|
| 656 |
fn=generate_image,
|
| 657 |
inputs=input_list,
|
| 658 |
+
outputs=[gallery, usage_tips, download_btn1, download_btn2]
|
| 659 |
)
|
| 660 |
|
| 661 |
# When user clicks on a suggestion, fill the prompt textbox and close popup
|