Download test
Browse files
app.py
CHANGED
|
@@ -23,6 +23,7 @@ else:
|
|
| 23 |
|
| 24 |
import gradio as gr
|
| 25 |
from diffusers.utils import load_image
|
|
|
|
| 26 |
from PIL import Image
|
| 27 |
from src.tryon_pipeline import StableDiffusionXLInpaintPipeline as TryonPipeline
|
| 28 |
from src.unet_hacked_garmnet import UNet2DConditionModel as UNet2DConditionModel_ref
|
|
@@ -422,7 +423,7 @@ background: linear-gradient(135deg, #CCFED9, #95BAFF);
|
|
| 422 |
html, body {
|
| 423 |
height: 100%;
|
| 424 |
margin: 0;
|
| 425 |
-
background: linear-gradient(135deg, #CCFED9, #95BAFF);
|
| 426 |
}
|
| 427 |
|
| 428 |
.gradio-container {
|
|
@@ -490,6 +491,17 @@ input[type="radio"]:checked + span {
|
|
| 490 |
|
| 491 |
'''
|
| 492 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 493 |
image_blocks = gr.Blocks(css=css).queue()
|
| 494 |
with image_blocks as demo:
|
| 495 |
gr.Markdown("## <span id='app-title'>Virtual Try-on</span>")
|
|
@@ -502,7 +514,6 @@ with image_blocks as demo:
|
|
| 502 |
is_checked_crop = gr.Checkbox(label="Yes", info="Use auto-crop & resizing",value=False)
|
| 503 |
|
| 504 |
|
| 505 |
-
|
| 506 |
with gr.Column():
|
| 507 |
garm_img = gr.Image(label="Garment", sources='upload', type="pil")
|
| 508 |
with gr.Row(elem_id="prompt-container"):
|
|
@@ -516,8 +527,7 @@ with image_blocks as demo:
|
|
| 516 |
with gr.Column():
|
| 517 |
# image_out = gr.Image(label="Output", elem_id="output-img", height=400)
|
| 518 |
image_out = gr.Image(label="Output", elem_id="output-img",show_share_button=False)
|
| 519 |
-
|
| 520 |
-
|
| 521 |
|
| 522 |
|
| 523 |
with gr.Column():
|
|
@@ -529,7 +539,13 @@ with image_blocks as demo:
|
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
-
try_button.click(fn=start_tryon, inputs=[imgs, garm_img, prompt, is_checked,is_checked_crop, denoise_steps, seed], outputs=[image_out,masked_img], api_name='tryon')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 533 |
|
| 534 |
image_blocks.launch(auth=(HF_TEST_USER_NAME, HF_PASS), show_error=True)
|
| 535 |
# image_blocks.launch(show_error=True)
|
|
|
|
| 23 |
|
| 24 |
import gradio as gr
|
| 25 |
from diffusers.utils import load_image
|
| 26 |
+
import tempfile
|
| 27 |
from PIL import Image
|
| 28 |
from src.tryon_pipeline import StableDiffusionXLInpaintPipeline as TryonPipeline
|
| 29 |
from src.unet_hacked_garmnet import UNet2DConditionModel as UNet2DConditionModel_ref
|
|
|
|
| 423 |
html, body {
|
| 424 |
height: 100%;
|
| 425 |
margin: 0;
|
| 426 |
+
background: linear-gradient(135deg, #CCFED9, #95BAFF) !important;
|
| 427 |
}
|
| 428 |
|
| 429 |
.gradio-container {
|
|
|
|
| 491 |
|
| 492 |
'''
|
| 493 |
|
| 494 |
+
def start_tryon_with_download(img_dict, garm_img, garment_des, is_checked, is_checked_crop, denoise_steps, seed):
|
| 495 |
+
# Call your existing start_tryon
|
| 496 |
+
output_img, mask_img = start_tryon(img_dict, garm_img, garment_des, is_checked, is_checked_crop, denoise_steps, seed)
|
| 497 |
+
|
| 498 |
+
# Save output image to temp file
|
| 499 |
+
tmp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".png")
|
| 500 |
+
output_img.save(tmp_file.name)
|
| 501 |
+
|
| 502 |
+
# Return images for display plus file path for download
|
| 503 |
+
return output_img, mask_img, tmp_file.name
|
| 504 |
+
|
| 505 |
image_blocks = gr.Blocks(css=css).queue()
|
| 506 |
with image_blocks as demo:
|
| 507 |
gr.Markdown("## <span id='app-title'>Virtual Try-on</span>")
|
|
|
|
| 514 |
is_checked_crop = gr.Checkbox(label="Yes", info="Use auto-crop & resizing",value=False)
|
| 515 |
|
| 516 |
|
|
|
|
| 517 |
with gr.Column():
|
| 518 |
garm_img = gr.Image(label="Garment", sources='upload', type="pil")
|
| 519 |
with gr.Row(elem_id="prompt-container"):
|
|
|
|
| 527 |
with gr.Column():
|
| 528 |
# image_out = gr.Image(label="Output", elem_id="output-img", height=400)
|
| 529 |
image_out = gr.Image(label="Output", elem_id="output-img",show_share_button=False)
|
| 530 |
+
download_btn = gr.DownloadButton(label="Download Generated Image")
|
|
|
|
| 531 |
|
| 532 |
|
| 533 |
with gr.Column():
|
|
|
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
+
# try_button.click(fn=start_tryon, inputs=[imgs, garm_img, prompt, is_checked,is_checked_crop, denoise_steps, seed], outputs=[image_out,masked_img], api_name='tryon')
|
| 543 |
+
try_button.click(
|
| 544 |
+
fn=start_tryon_with_download,
|
| 545 |
+
inputs=[imgs, garm_img, prompt, is_checked, is_checked_crop, denoise_steps, seed],
|
| 546 |
+
outputs=[image_out, masked_img, download_btn],
|
| 547 |
+
api_name='tryon'
|
| 548 |
+
)
|
| 549 |
|
| 550 |
image_blocks.launch(auth=(HF_TEST_USER_NAME, HF_PASS), show_error=True)
|
| 551 |
# image_blocks.launch(show_error=True)
|