Spaces:
Running
Running
Update user_dress.py
Browse files- user_dress.py +10 -34
user_dress.py
CHANGED
@@ -4,10 +4,11 @@ import os
|
|
4 |
from PIL import Image
|
5 |
import requests
|
6 |
import time
|
|
|
7 |
|
8 |
UPLOAD_FOLDER = 'uploads'
|
9 |
DOWNLOAD_FOLDER = 'downloads'
|
10 |
-
|
11 |
|
12 |
def user_dress_cat(user_pic, cloth_gen, index):
|
13 |
time_1 = time.time()
|
@@ -40,7 +41,7 @@ def user_dress_cat(user_pic, cloth_gen, index):
|
|
40 |
url_time = time_2 - time_1
|
41 |
print(f"url_time:{url_time}")
|
42 |
time_1 = time.time()
|
43 |
-
|
44 |
if response.status_code == 200:
|
45 |
filename = os.path.join(save_directory, f"cat-vton_{index}.png")
|
46 |
with open(filename, 'wb') as f:
|
@@ -53,7 +54,7 @@ def user_dress_cat(user_pic, cloth_gen, index):
|
|
53 |
return os.path.join(save_directory, f"cat-vton_{index}.png")
|
54 |
|
55 |
|
56 |
-
def
|
57 |
time_1 = time.time()
|
58 |
filename_1 = 'user_image.jpg'
|
59 |
filename_2 = 'cloth_image.jpg'
|
@@ -65,42 +66,17 @@ def user_dress_idm(user_pic, cloth_gen, index):
|
|
65 |
save_time = time_2 - time_1
|
66 |
print(f"save_time:{save_time}")
|
67 |
time_1 = time.time()
|
68 |
-
|
69 |
-
"fal-ai/idm-vton",
|
70 |
-
arguments={
|
71 |
-
"human_image_url": fal_client.upload_file(file_path_1),
|
72 |
-
"garment_image_url": fal_client.upload_file(file_path_2),
|
73 |
-
"description": "long-sleeved long coat"
|
74 |
-
},
|
75 |
-
)
|
76 |
-
request_id = handler.request_id
|
77 |
-
result = fal_client.result("fal-ai/idm-vton", request_id)
|
78 |
time_2 = time.time()
|
79 |
cat_time = time_2 - time_1
|
80 |
-
print(f"
|
81 |
-
time_1 = time.time()
|
82 |
-
response = requests.get(result['image']['url'])
|
83 |
-
time_2 = time.time()
|
84 |
-
url_time = time_2 - time_1
|
85 |
-
print(f"url_time:{url_time}")
|
86 |
-
time_1 = time.time()
|
87 |
-
save_directory = "downloads"
|
88 |
-
if response.status_code == 200:
|
89 |
-
filename = os.path.join(save_directory, f"idm-vton_{index}.png")
|
90 |
-
with open(filename, 'wb') as f:
|
91 |
-
f.write(response.content)
|
92 |
-
else:
|
93 |
-
print(f"Failed to download image from {result['image']['url']}")
|
94 |
-
time_2 = time.time()
|
95 |
-
downloads_time = time_2 - time_1
|
96 |
-
print(f"downloads_time:{downloads_time}")
|
97 |
-
return os.path.join(save_directory, f"idm-vton_{index}.png")
|
98 |
|
99 |
|
100 |
def user_cloths(user_pic, cloth_gen):
|
101 |
user_cloth = []
|
102 |
-
for i in range(1,
|
103 |
user_cloth.append(user_dress_cat(user_pic, cloth_gen, i))
|
104 |
-
|
105 |
-
|
|
|
106 |
return user_cloth
|
|
|
4 |
from PIL import Image
|
5 |
import requests
|
6 |
import time
|
7 |
+
from kolorsvton1024 import kolor_vton
|
8 |
|
9 |
UPLOAD_FOLDER = 'uploads'
|
10 |
DOWNLOAD_FOLDER = 'downloads'
|
11 |
+
save_directory = "downloads"
|
12 |
|
13 |
def user_dress_cat(user_pic, cloth_gen, index):
|
14 |
time_1 = time.time()
|
|
|
41 |
url_time = time_2 - time_1
|
42 |
print(f"url_time:{url_time}")
|
43 |
time_1 = time.time()
|
44 |
+
|
45 |
if response.status_code == 200:
|
46 |
filename = os.path.join(save_directory, f"cat-vton_{index}.png")
|
47 |
with open(filename, 'wb') as f:
|
|
|
54 |
return os.path.join(save_directory, f"cat-vton_{index}.png")
|
55 |
|
56 |
|
57 |
+
def user_dress_kolor(user_pic, cloth_gen, index):
|
58 |
time_1 = time.time()
|
59 |
filename_1 = 'user_image.jpg'
|
60 |
filename_2 = 'cloth_image.jpg'
|
|
|
66 |
save_time = time_2 - time_1
|
67 |
print(f"save_time:{save_time}")
|
68 |
time_1 = time.time()
|
69 |
+
kolor_vton(file_path_1, file_path_2, index)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
time_2 = time.time()
|
71 |
cat_time = time_2 - time_1
|
72 |
+
print(f"kolor_time:{cat_time}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
|
74 |
|
75 |
def user_cloths(user_pic, cloth_gen):
|
76 |
user_cloth = []
|
77 |
+
for i in range(1, 4):
|
78 |
user_cloth.append(user_dress_cat(user_pic, cloth_gen, i))
|
79 |
+
for i in range(4, 7):
|
80 |
+
user_dress_kolor(user_pic, cloth_gen, i)
|
81 |
+
user_cloth.append(os.path.join(save_directory, f"kolor/kolor_{i}.png"))
|
82 |
return user_cloth
|