Spaces:
Running
on
Zero
Running
on
Zero
Add log for show start up steps
Browse files
app.py
CHANGED
|
@@ -27,7 +27,7 @@ from preprocess.humanparsing.run_parsing import Parsing
|
|
| 27 |
from preprocess.openpose.run_openpose import OpenPose
|
| 28 |
from detectron2.data.detection_utils import convert_PIL_to_numpy,_apply_exif_orientation
|
| 29 |
from torchvision.transforms.functional import to_pil_image
|
| 30 |
-
import pillow_heif # HEIC ์ด๋ฏธ์ง ์ฒ๋ฆฌ์ฉ (์์ดํฐ ์ดฌ์ ์ฌ์ง ํฌ๋งท)
|
| 31 |
from urllib.parse import urlparse
|
| 32 |
|
| 33 |
# SSL ๊ฒฝ๊ณ ์ต์
|
|
@@ -52,15 +52,23 @@ def pil_to_binary_mask(pil_image, threshold=0):
|
|
| 52 |
return output_mask
|
| 53 |
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
base_path = 'yisol/IDM-VTON'
|
| 56 |
example_path = os.path.join(os.path.dirname(__file__), 'example')
|
| 57 |
|
|
|
|
| 58 |
unet = UNet2DConditionModel.from_pretrained(
|
| 59 |
base_path,
|
| 60 |
subfolder="unet",
|
| 61 |
torch_dtype=torch.float16,
|
| 62 |
)
|
| 63 |
unet.requires_grad_(False)
|
|
|
|
|
|
|
|
|
|
| 64 |
tokenizer_one = AutoTokenizer.from_pretrained(
|
| 65 |
base_path,
|
| 66 |
subfolder="tokenizer",
|
|
@@ -73,8 +81,13 @@ tokenizer_two = AutoTokenizer.from_pretrained(
|
|
| 73 |
revision=None,
|
| 74 |
use_fast=False,
|
| 75 |
)
|
|
|
|
|
|
|
|
|
|
| 76 |
noise_scheduler = DDPMScheduler.from_pretrained(base_path, subfolder="scheduler")
|
|
|
|
| 77 |
|
|
|
|
| 78 |
text_encoder_one = CLIPTextModel.from_pretrained(
|
| 79 |
base_path,
|
| 80 |
subfolder="text_encoder",
|
|
@@ -85,26 +98,37 @@ text_encoder_two = CLIPTextModelWithProjection.from_pretrained(
|
|
| 85 |
subfolder="text_encoder_2",
|
| 86 |
torch_dtype=torch.float16,
|
| 87 |
)
|
|
|
|
|
|
|
|
|
|
| 88 |
image_encoder = CLIPVisionModelWithProjection.from_pretrained(
|
| 89 |
base_path,
|
| 90 |
subfolder="image_encoder",
|
| 91 |
torch_dtype=torch.float16,
|
| 92 |
)
|
|
|
|
|
|
|
|
|
|
| 93 |
vae = AutoencoderKL.from_pretrained(base_path,
|
| 94 |
subfolder="vae",
|
| 95 |
torch_dtype=torch.float16,
|
| 96 |
)
|
|
|
|
| 97 |
|
| 98 |
-
|
| 99 |
UNet_Encoder = UNet2DConditionModel_ref.from_pretrained(
|
| 100 |
base_path,
|
| 101 |
subfolder="unet_encoder",
|
| 102 |
torch_dtype=torch.float16,
|
| 103 |
)
|
|
|
|
| 104 |
|
|
|
|
| 105 |
parsing_model = Parsing(0)
|
| 106 |
openpose_model = OpenPose(0)
|
|
|
|
| 107 |
|
|
|
|
| 108 |
UNet_Encoder.requires_grad_(False)
|
| 109 |
image_encoder.requires_grad_(False)
|
| 110 |
vae.requires_grad_(False)
|
|
@@ -117,7 +141,9 @@ tensor_transfrom = transforms.Compose(
|
|
| 117 |
transforms.Normalize([0.5], [0.5]),
|
| 118 |
]
|
| 119 |
)
|
|
|
|
| 120 |
|
|
|
|
| 121 |
pipe = TryonPipeline.from_pretrained(
|
| 122 |
base_path,
|
| 123 |
unet=unet,
|
|
@@ -132,6 +158,11 @@ pipe = TryonPipeline.from_pretrained(
|
|
| 132 |
torch_dtype=torch.float16,
|
| 133 |
)
|
| 134 |
pipe.unet_encoder = UNet_Encoder
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
|
| 136 |
|
| 137 |
# ์ด๋ฏธ์ง ์ ์ฒ๋ฆฌ ํจ์
|
|
@@ -316,16 +347,28 @@ def download_all_models():
|
|
| 316 |
print("Checking and downloading required model files...")
|
| 317 |
|
| 318 |
# Download DensePose model
|
| 319 |
-
print("\n
|
| 320 |
densepose_success = download_densepose_model()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 321 |
|
| 322 |
# Download OpenPose model
|
| 323 |
-
print("\n
|
| 324 |
openpose_success = download_openpose_model()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 325 |
|
| 326 |
# Download Human Parsing models
|
| 327 |
-
print("\n
|
| 328 |
parsing_success = download_humanparsing_models()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 329 |
|
| 330 |
return densepose_success and openpose_success and parsing_success
|
| 331 |
|
|
@@ -460,20 +503,30 @@ def start_tryon(dict,garm_img,garment_des,is_checked,denoise_steps,seed, is_chec
|
|
| 460 |
return images[0], mask_gray
|
| 461 |
# return images[0], mask_gray
|
| 462 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 463 |
garm_list = os.listdir(os.path.join(example_path,"cloth"))
|
| 464 |
garm_list_path = [os.path.join(example_path,"cloth",garm) for garm in garm_list]
|
|
|
|
| 465 |
|
| 466 |
human_list = os.listdir(os.path.join(example_path,"human"))
|
| 467 |
human_list_path = [os.path.join(example_path,"human",human) for human in human_list]
|
|
|
|
| 468 |
|
| 469 |
# human_ex_list๋ฅผ ๋จ์ํ ์ด๋ฏธ์ง ๊ฒฝ๋ก ๋ฆฌ์คํธ๋ก ๋ณ๊ฒฝ (๊ทธ๋ฆฌ๋ ํ์๋ฅผ ์ํด)
|
| 470 |
human_ex_list = human_list_path
|
| 471 |
|
| 472 |
##default human
|
| 473 |
|
|
|
|
|
|
|
|
|
|
| 474 |
|
| 475 |
image_blocks = gr.Blocks().queue()
|
| 476 |
with image_blocks as demo:
|
|
|
|
| 477 |
|
| 478 |
gr.Markdown("## DXCO : GENAI-VTON")
|
| 479 |
gr.Markdown("์์ฑ๋จ, ์ค์ง์, ์กฐ๋ฏผ์ฃผ based on IDM-VTON")
|
|
@@ -549,21 +602,36 @@ with image_blocks as demo:
|
|
| 549 |
outputs=[image_out, masked_img],
|
| 550 |
api_name='tryon'
|
| 551 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 552 |
|
| 553 |
# DensePose ๋ชจ๋ธ ๋ค์ด๋ก๋
|
| 554 |
-
print("
|
|
|
|
|
|
|
| 555 |
try:
|
| 556 |
download_all_models()
|
| 557 |
-
print("All model files downloaded successfully.")
|
| 558 |
except Exception as e:
|
| 559 |
-
print(f"Warning: Could not download all model files: {e}")
|
| 560 |
print("The models will be downloaded when needed during inference.")
|
| 561 |
|
| 562 |
# ์ฑ ์คํ
|
|
|
|
|
|
|
|
|
|
| 563 |
if __name__ == "__main__":
|
| 564 |
try:
|
| 565 |
-
print("Starting GENAI-VTON application
|
|
|
|
| 566 |
image_blocks.launch(server_name="0.0.0.0", server_port=7860, share=False)
|
| 567 |
except Exception as e:
|
| 568 |
-
print(f"Error starting the application: {e}")
|
| 569 |
print("Please check if all required dependencies are installed.")
|
|
|
|
|
|
|
|
|
| 27 |
from preprocess.openpose.run_openpose import OpenPose
|
| 28 |
from detectron2.data.detection_utils import convert_PIL_to_numpy,_apply_exif_orientation
|
| 29 |
from torchvision.transforms.functional import to_pil_image
|
| 30 |
+
# import pillow_heif # HEIC ์ด๋ฏธ์ง ์ฒ๋ฆฌ์ฉ (์์ดํฐ ์ดฌ์ ์ฌ์ง ํฌ๋งท)
|
| 31 |
from urllib.parse import urlparse
|
| 32 |
|
| 33 |
# SSL ๊ฒฝ๊ณ ์ต์
|
|
|
|
| 52 |
return output_mask
|
| 53 |
|
| 54 |
|
| 55 |
+
print("=" * 60)
|
| 56 |
+
print("Starting GENAI-VTON Application Initialization")
|
| 57 |
+
print("=" * 60)
|
| 58 |
+
|
| 59 |
base_path = 'yisol/IDM-VTON'
|
| 60 |
example_path = os.path.join(os.path.dirname(__file__), 'example')
|
| 61 |
|
| 62 |
+
print("\n[1/10] Loading UNet model...")
|
| 63 |
unet = UNet2DConditionModel.from_pretrained(
|
| 64 |
base_path,
|
| 65 |
subfolder="unet",
|
| 66 |
torch_dtype=torch.float16,
|
| 67 |
)
|
| 68 |
unet.requires_grad_(False)
|
| 69 |
+
print("โ UNet model loaded successfully")
|
| 70 |
+
|
| 71 |
+
print("\n[2/10] Loading tokenizers...")
|
| 72 |
tokenizer_one = AutoTokenizer.from_pretrained(
|
| 73 |
base_path,
|
| 74 |
subfolder="tokenizer",
|
|
|
|
| 81 |
revision=None,
|
| 82 |
use_fast=False,
|
| 83 |
)
|
| 84 |
+
print("โ Tokenizers loaded successfully")
|
| 85 |
+
|
| 86 |
+
print("\n[3/10] Loading noise scheduler...")
|
| 87 |
noise_scheduler = DDPMScheduler.from_pretrained(base_path, subfolder="scheduler")
|
| 88 |
+
print("โ Noise scheduler loaded successfully")
|
| 89 |
|
| 90 |
+
print("\n[4/10] Loading text encoders...")
|
| 91 |
text_encoder_one = CLIPTextModel.from_pretrained(
|
| 92 |
base_path,
|
| 93 |
subfolder="text_encoder",
|
|
|
|
| 98 |
subfolder="text_encoder_2",
|
| 99 |
torch_dtype=torch.float16,
|
| 100 |
)
|
| 101 |
+
print("โ Text encoders loaded successfully")
|
| 102 |
+
|
| 103 |
+
print("\n[5/10] Loading image encoder...")
|
| 104 |
image_encoder = CLIPVisionModelWithProjection.from_pretrained(
|
| 105 |
base_path,
|
| 106 |
subfolder="image_encoder",
|
| 107 |
torch_dtype=torch.float16,
|
| 108 |
)
|
| 109 |
+
print("โ Image encoder loaded successfully")
|
| 110 |
+
|
| 111 |
+
print("\n[6/10] Loading VAE...")
|
| 112 |
vae = AutoencoderKL.from_pretrained(base_path,
|
| 113 |
subfolder="vae",
|
| 114 |
torch_dtype=torch.float16,
|
| 115 |
)
|
| 116 |
+
print("โ VAE loaded successfully")
|
| 117 |
|
| 118 |
+
print("\n[7/10] Loading UNet Encoder...")
|
| 119 |
UNet_Encoder = UNet2DConditionModel_ref.from_pretrained(
|
| 120 |
base_path,
|
| 121 |
subfolder="unet_encoder",
|
| 122 |
torch_dtype=torch.float16,
|
| 123 |
)
|
| 124 |
+
print("โ UNet Encoder loaded successfully")
|
| 125 |
|
| 126 |
+
print("\n[8/10] Initializing parsing and openpose models...")
|
| 127 |
parsing_model = Parsing(0)
|
| 128 |
openpose_model = OpenPose(0)
|
| 129 |
+
print("โ Parsing and OpenPose models initialized")
|
| 130 |
|
| 131 |
+
print("\n[9/10] Configuring model parameters...")
|
| 132 |
UNet_Encoder.requires_grad_(False)
|
| 133 |
image_encoder.requires_grad_(False)
|
| 134 |
vae.requires_grad_(False)
|
|
|
|
| 141 |
transforms.Normalize([0.5], [0.5]),
|
| 142 |
]
|
| 143 |
)
|
| 144 |
+
print("โ Model parameters configured")
|
| 145 |
|
| 146 |
+
print("\n[10/10] Initializing TryonPipeline...")
|
| 147 |
pipe = TryonPipeline.from_pretrained(
|
| 148 |
base_path,
|
| 149 |
unet=unet,
|
|
|
|
| 158 |
torch_dtype=torch.float16,
|
| 159 |
)
|
| 160 |
pipe.unet_encoder = UNet_Encoder
|
| 161 |
+
print("โ TryonPipeline initialized successfully")
|
| 162 |
+
|
| 163 |
+
print("\n" + "=" * 60)
|
| 164 |
+
print("All models loaded successfully!")
|
| 165 |
+
print("=" * 60 + "\n")
|
| 166 |
|
| 167 |
|
| 168 |
# ์ด๋ฏธ์ง ์ ์ฒ๋ฆฌ ํจ์
|
|
|
|
| 347 |
print("Checking and downloading required model files...")
|
| 348 |
|
| 349 |
# Download DensePose model
|
| 350 |
+
print("\n[1/3] Downloading DensePose model...")
|
| 351 |
densepose_success = download_densepose_model()
|
| 352 |
+
if densepose_success:
|
| 353 |
+
print("โ DensePose model ready")
|
| 354 |
+
else:
|
| 355 |
+
print("โ DensePose model download failed (will download on demand)")
|
| 356 |
|
| 357 |
# Download OpenPose model
|
| 358 |
+
print("\n[2/3] Downloading OpenPose model...")
|
| 359 |
openpose_success = download_openpose_model()
|
| 360 |
+
if openpose_success:
|
| 361 |
+
print("โ OpenPose model ready")
|
| 362 |
+
else:
|
| 363 |
+
print("โ OpenPose model download failed (will download on demand)")
|
| 364 |
|
| 365 |
# Download Human Parsing models
|
| 366 |
+
print("\n[3/3] Downloading Human Parsing models...")
|
| 367 |
parsing_success = download_humanparsing_models()
|
| 368 |
+
if parsing_success:
|
| 369 |
+
print("โ Human Parsing models ready")
|
| 370 |
+
else:
|
| 371 |
+
print("โ Human Parsing models download failed (will download on demand)")
|
| 372 |
|
| 373 |
return densepose_success and openpose_success and parsing_success
|
| 374 |
|
|
|
|
| 503 |
return images[0], mask_gray
|
| 504 |
# return images[0], mask_gray
|
| 505 |
|
| 506 |
+
print("\n" + "=" * 60)
|
| 507 |
+
print("Loading Example Images...")
|
| 508 |
+
print("=" * 60)
|
| 509 |
+
|
| 510 |
garm_list = os.listdir(os.path.join(example_path,"cloth"))
|
| 511 |
garm_list_path = [os.path.join(example_path,"cloth",garm) for garm in garm_list]
|
| 512 |
+
print(f"โ Found {len(garm_list_path)} garment example images")
|
| 513 |
|
| 514 |
human_list = os.listdir(os.path.join(example_path,"human"))
|
| 515 |
human_list_path = [os.path.join(example_path,"human",human) for human in human_list]
|
| 516 |
+
print(f"โ Found {len(human_list_path)} human example images")
|
| 517 |
|
| 518 |
# human_ex_list๋ฅผ ๋จ์ํ ์ด๋ฏธ์ง ๊ฒฝ๋ก ๋ฆฌ์คํธ๋ก ๋ณ๊ฒฝ (๊ทธ๋ฆฌ๋ ํ์๋ฅผ ์ํด)
|
| 519 |
human_ex_list = human_list_path
|
| 520 |
|
| 521 |
##default human
|
| 522 |
|
| 523 |
+
print("\n" + "=" * 60)
|
| 524 |
+
print("Creating Gradio Application Interface...")
|
| 525 |
+
print("=" * 60)
|
| 526 |
|
| 527 |
image_blocks = gr.Blocks().queue()
|
| 528 |
with image_blocks as demo:
|
| 529 |
+
print("โ Gradio Blocks created")
|
| 530 |
|
| 531 |
gr.Markdown("## DXCO : GENAI-VTON")
|
| 532 |
gr.Markdown("์์ฑ๋จ, ์ค์ง์, ์กฐ๋ฏผ์ฃผ based on IDM-VTON")
|
|
|
|
| 602 |
outputs=[image_out, masked_img],
|
| 603 |
api_name='tryon'
|
| 604 |
)
|
| 605 |
+
|
| 606 |
+
print("โ Gradio interface components created")
|
| 607 |
+
print("โ Event handlers configured")
|
| 608 |
+
|
| 609 |
+
print("\n" + "=" * 60)
|
| 610 |
+
print("Gradio Application Interface Created Successfully!")
|
| 611 |
+
print("=" * 60)
|
| 612 |
|
| 613 |
# DensePose ๋ชจ๋ธ ๋ค์ด๋ก๋
|
| 614 |
+
print("\n" + "=" * 60)
|
| 615 |
+
print("Checking and Downloading Additional Models...")
|
| 616 |
+
print("=" * 60)
|
| 617 |
try:
|
| 618 |
download_all_models()
|
| 619 |
+
print("\nโ All model files downloaded successfully.")
|
| 620 |
except Exception as e:
|
| 621 |
+
print(f"\nโ Warning: Could not download all model files: {e}")
|
| 622 |
print("The models will be downloaded when needed during inference.")
|
| 623 |
|
| 624 |
# ์ฑ ์คํ
|
| 625 |
+
print("\n" + "=" * 60)
|
| 626 |
+
print("Launching Application Server...")
|
| 627 |
+
print("=" * 60)
|
| 628 |
if __name__ == "__main__":
|
| 629 |
try:
|
| 630 |
+
print("Starting GENAI-VTON application on http://0.0.0.0:7860")
|
| 631 |
+
print("Please wait while the server starts...")
|
| 632 |
image_blocks.launch(server_name="0.0.0.0", server_port=7860, share=False)
|
| 633 |
except Exception as e:
|
| 634 |
+
print(f"\nโ Error starting the application: {e}")
|
| 635 |
print("Please check if all required dependencies are installed.")
|
| 636 |
+
import traceback
|
| 637 |
+
traceback.print_exc()
|