Spaces:
Sleeping
Sleeping
LFS file download and load in the code
Browse files
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 =
|
| 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 =
|
| 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 =
|
| 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.
|
| 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 |
-
|
| 493 |
-
|
| 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.")
|