Spaces:
Sleeping
Sleeping
User LFS download
Browse files
app.py
CHANGED
|
@@ -207,11 +207,64 @@ def process_url_image(url):
|
|
| 207 |
img = load_image_from_url(url)
|
| 208 |
if img is None:
|
| 209 |
print("Failed to load image from URL")
|
| 210 |
-
return None
|
| 211 |
-
|
| 212 |
return preprocess_image(img)
|
| 213 |
|
| 214 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 215 |
@spaces.GPU
|
| 216 |
def start_tryon(dict,garm_img,garment_des,is_checked,denoise_steps,seed, is_checked_crop):
|
| 217 |
device = "cuda"
|
|
@@ -256,7 +309,13 @@ def start_tryon(dict,garm_img,garment_des,is_checked,denoise_steps,seed, is_chec
|
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 260 |
# verbosity = getattr(args, "verbosity", None)
|
| 261 |
pose_img = args.func(args,human_img_arg)
|
| 262 |
pose_img = pose_img[:,:,::-1]
|
|
@@ -428,3 +487,9 @@ with image_blocks as demo:
|
|
| 428 |
)
|
| 429 |
|
| 430 |
image_blocks.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
img = load_image_from_url(url)
|
| 208 |
if img is None:
|
| 209 |
print("Failed to load image from URL")
|
| 210 |
+
return None
|
| 211 |
+
|
| 212 |
return preprocess_image(img)
|
| 213 |
|
| 214 |
|
| 215 |
+
# Hugging Face LFS OID๋ฅผ ์ฌ์ฉํ์ฌ densepose ๋ชจ๋ธ ๋ค์ด๋ก๋
|
| 216 |
+
def download_densepose_model():
|
| 217 |
+
"""
|
| 218 |
+
Hugging Face LFS OID๋ฅผ ์ฌ์ฉํ์ฌ densepose ๋ชจ๋ธ์ ๋ค์ด๋ก๋ํฉ๋๋ค.
|
| 219 |
+
OID: b8a7382001b16e453bad95ca9dbc68ae8f2b839b304cf90eaf5c27fbdb4dae91
|
| 220 |
+
"""
|
| 221 |
+
model_path = './ckpt/densepose/model_final_162be9.pkl'
|
| 222 |
+
|
| 223 |
+
# ๋ชจ๋ธ ํ์ผ์ด ์ด๋ฏธ ์กด์ฌํ๋์ง ํ์ธ
|
| 224 |
+
if os.path.exists(model_path):
|
| 225 |
+
print(f"DensePose model already exists at {model_path}")
|
| 226 |
+
return model_path
|
| 227 |
+
|
| 228 |
+
# ๋๋ ํ ๋ฆฌ ์์ฑ
|
| 229 |
+
os.makedirs('./ckpt/densepose', exist_ok=True)
|
| 230 |
+
|
| 231 |
+
# Hugging Face LFS OID๋ฅผ ์ฌ์ฉํ ๋ค์ด๋ก๋ URL
|
| 232 |
+
oid = "b8a7382001b16e453bad95ca9dbc68ae8f2b839b304cf90eaf5c27fbdb4dae91"
|
| 233 |
+
download_url = f"https://huggingface.co/datasets/hf-internal-testing/fixtures/resolve/{oid}/model_final_162be9.pkl"
|
| 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:
|
| 241 |
+
for chunk in response.iter_content(chunk_size=8192):
|
| 242 |
+
f.write(chunk)
|
| 243 |
+
|
| 244 |
+
print(f"DensePose model downloaded successfully to {model_path}")
|
| 245 |
+
return model_path
|
| 246 |
+
|
| 247 |
+
except Exception as e:
|
| 248 |
+
print(f"Error downloading DensePose model: {e}")
|
| 249 |
+
# ๋์ฒด URL ์๋
|
| 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:
|
| 257 |
+
for chunk in response.iter_content(chunk_size=8192):
|
| 258 |
+
f.write(chunk)
|
| 259 |
+
|
| 260 |
+
print(f"DensePose model downloaded successfully from fallback URL to {model_path}")
|
| 261 |
+
return model_path
|
| 262 |
+
|
| 263 |
+
except Exception as e2:
|
| 264 |
+
print(f"Error downloading from fallback URL: {e2}")
|
| 265 |
+
return None
|
| 266 |
+
|
| 267 |
+
|
| 268 |
@spaces.GPU
|
| 269 |
def start_tryon(dict,garm_img,garment_des,is_checked,denoise_steps,seed, is_checked_crop):
|
| 270 |
device = "cuda"
|
|
|
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
+
# DensePose ๋ชจ๋ธ ๋ค์ด๋ก๋ ๋ฐ ๊ฒฝ๋ก ์ค์
|
| 313 |
+
densepose_model_path = download_densepose_model()
|
| 314 |
+
if densepose_model_path is None:
|
| 315 |
+
print("Failed to download DensePose model, using default path")
|
| 316 |
+
densepose_model_path = './ckpt/densepose/model_final_162be9.pkl'
|
| 317 |
+
|
| 318 |
+
args = apply_net.create_argument_parser().parse_args(('show', './configs/densepose_rcnn_R_50_FPN_s1x.yaml', densepose_model_path, 'dp_segm', '-v', '--opts', 'MODEL.DEVICE', 'cuda'))
|
| 319 |
# verbosity = getattr(args, "verbosity", None)
|
| 320 |
pose_img = args.func(args,human_img_arg)
|
| 321 |
pose_img = pose_img[:,:,::-1]
|
|
|
|
| 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.")
|