nami0342 commited on
Commit
a5dbfe3
ยท
1 Parent(s): 87a611c

LFS file download and load in the code

Browse files
Files changed (1) hide show
  1. app.py +27 -9
app.py CHANGED
@@ -16,6 +16,8 @@ from typing import List
16
  import torch
17
  import os
18
  import io
 
 
19
  from transformers import AutoTokenizer
20
  import numpy as np
21
  from utils_mask import get_mask_location
@@ -26,9 +28,15 @@ from preprocess.openpose.run_openpose import OpenPose
26
  from detectron2.data.detection_utils import convert_PIL_to_numpy,_apply_exif_orientation
27
  from torchvision.transforms.functional import to_pil_image
28
  import pillow_heif # HEIC ์ด๋ฏธ์ง€ ์ฒ˜๋ฆฌ์šฉ (์•„์ดํฐ ์ดฌ์˜ ์‚ฌ์ง„ ํฌ๋งท)
29
- import requests
30
  from urllib.parse import urlparse
31
 
 
 
 
 
 
 
 
32
 
33
  def pil_to_binary_mask(pil_image, threshold=0):
34
  np_image = np.array(pil_image)
@@ -166,7 +174,7 @@ def preprocess_image(image):
166
  # URL์—์„œ ์ด๋ฏธ์ง€ ๊ฐ€์ ธ์˜ค๊ธฐ ํ•จ์ˆ˜
167
  def load_image_from_url(url):
168
  try:
169
- response = requests.get(url, stream=True, timeout=10)
170
  response.raise_for_status() # HTTP ์˜ค๋ฅ˜ ํ™•์ธ
171
 
172
  # ์ด๋ฏธ์ง€ ๋‹ค์šด๋กœ๋“œ
@@ -234,7 +242,7 @@ def download_densepose_model():
234
 
235
  try:
236
  print(f"Downloading DensePose model from {download_url}")
237
- response = requests.get(download_url, stream=True, timeout=300)
238
  response.raise_for_status()
239
 
240
  with open(model_path, 'wb') as f:
@@ -250,7 +258,7 @@ def download_densepose_model():
250
  fallback_url = "https://dl.fbaipublicfiles.com/densepose/densepose_rcnn_R_50_FPN_s1x/165712039/model_final_162be9.pkl"
251
  try:
252
  print(f"Trying fallback URL: {fallback_url}")
253
- response = requests.get(fallback_url, stream=True, timeout=300)
254
  response.raise_for_status()
255
 
256
  with open(model_path, 'wb') as f:
@@ -455,7 +463,7 @@ with image_blocks as demo:
455
  # is_checked = gr.Number(value=True)
456
 
457
  # ์ด๋ฏธ์ง€ ์—…๋กœ๋“œ ์‹œ ์ „์ฒ˜๋ฆฌ
458
- imgs.upload(
459
  fn=preprocess_image,
460
  inputs=imgs,
461
  outputs=imgs, # ์ „์ฒ˜๋ฆฌ๋œ ์ด๋ฏธ์ง€๋ฅผ ImageEditor์— ๋‹ค์‹œ ํ‘œ์‹œ
@@ -486,10 +494,20 @@ with image_blocks as demo:
486
  api_name='tryon'
487
  )
488
 
489
- image_blocks.launch()
490
-
491
  # ์•ฑ ์‹œ์ž‘ ์‹œ DensePose ๋ชจ๋ธ ๋ฏธ๋ฆฌ ๋‹ค์šด๋กœ๋“œ
492
- if __name__ == "__main__":
493
- print("Initializing DensePose model...")
494
  download_densepose_model()
495
  print("DensePose model initialization completed.")
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  import torch
17
  import os
18
  import io
19
+ import warnings
20
+ import requests
21
  from transformers import AutoTokenizer
22
  import numpy as np
23
  from utils_mask import get_mask_location
 
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 ๊ฒฝ๊ณ  ์–ต์ œ
34
+ warnings.filterwarnings("ignore", message=".*OpenSSL.*")
35
+ warnings.filterwarnings("ignore", category=UserWarning, module="urllib3")
36
+
37
+ # requests ์„ธ์…˜ ์„ค์ •
38
+ session = requests.Session()
39
+ session.verify = False # SSL ๊ฒ€์ฆ ๋น„ํ™œ์„ฑํ™” (๊ฐœ๋ฐœ ํ™˜๊ฒฝ์šฉ)
40
 
41
  def pil_to_binary_mask(pil_image, threshold=0):
42
  np_image = np.array(pil_image)
 
174
  # URL์—์„œ ์ด๋ฏธ์ง€ ๊ฐ€์ ธ์˜ค๊ธฐ ํ•จ์ˆ˜
175
  def load_image_from_url(url):
176
  try:
177
+ response = session.get(url, stream=True, timeout=10)
178
  response.raise_for_status() # HTTP ์˜ค๋ฅ˜ ํ™•์ธ
179
 
180
  # ์ด๋ฏธ์ง€ ๋‹ค์šด๋กœ๋“œ
 
242
 
243
  try:
244
  print(f"Downloading DensePose model from {download_url}")
245
+ response = session.get(download_url, stream=True, timeout=300)
246
  response.raise_for_status()
247
 
248
  with open(model_path, 'wb') as f:
 
258
  fallback_url = "https://dl.fbaipublicfiles.com/densepose/densepose_rcnn_R_50_FPN_s1x/165712039/model_final_162be9.pkl"
259
  try:
260
  print(f"Trying fallback URL: {fallback_url}")
261
+ response = session.get(fallback_url, stream=True, timeout=300)
262
  response.raise_for_status()
263
 
264
  with open(model_path, 'wb') as f:
 
463
  # is_checked = gr.Number(value=True)
464
 
465
  # ์ด๋ฏธ์ง€ ์—…๋กœ๋“œ ์‹œ ์ „์ฒ˜๋ฆฌ
466
+ imgs.change(
467
  fn=preprocess_image,
468
  inputs=imgs,
469
  outputs=imgs, # ์ „์ฒ˜๋ฆฌ๋œ ์ด๋ฏธ์ง€๋ฅผ ImageEditor์— ๋‹ค์‹œ ํ‘œ์‹œ
 
494
  api_name='tryon'
495
  )
496
 
 
 
497
  # ์•ฑ ์‹œ์ž‘ ์‹œ DensePose ๋ชจ๋ธ ๋ฏธ๋ฆฌ ๋‹ค์šด๋กœ๋“œ
498
+ print("Initializing DensePose model...")
499
+ try:
500
  download_densepose_model()
501
  print("DensePose model initialization completed.")
502
+ except Exception as e:
503
+ print(f"Warning: Could not download DensePose model: {e}")
504
+ print("The model will be downloaded when needed during inference.")
505
+
506
+ # ์•ฑ ์‹คํ–‰
507
+ if __name__ == "__main__":
508
+ try:
509
+ print("Starting GENAI-VTON application...")
510
+ image_blocks.launch(server_name="0.0.0.0", server_port=7860, share=False)
511
+ except Exception as e:
512
+ print(f"Error starting the application: {e}")
513
+ print("Please check if all required dependencies are installed.")