Spaces:
Sleeping
Sleeping
Delete user_dress.py
Browse files- user_dress.py +0 -54
user_dress.py
DELETED
@@ -1,54 +0,0 @@
|
|
1 |
-
from io import BytesIO
|
2 |
-
import fal_client
|
3 |
-
import os
|
4 |
-
from PIL import Image
|
5 |
-
import requests
|
6 |
-
import time
|
7 |
-
|
8 |
-
UPLOAD_FOLDER = 'uploads'
|
9 |
-
DOWNLOAD_FOLDER = 'downloads'
|
10 |
-
|
11 |
-
def user_dress(user_pic, cloth_gen):
|
12 |
-
time_1 = time.time()
|
13 |
-
filename_1 = 'user_image.jpg'
|
14 |
-
filename_2 = 'cloth_image.jpg'
|
15 |
-
file_path_1 = os.path.join(UPLOAD_FOLDER, filename_1)
|
16 |
-
file_path_2 = os.path.join(UPLOAD_FOLDER, filename_2)
|
17 |
-
Image.fromarray(user_pic).save(file_path_1)
|
18 |
-
Image.fromarray(cloth_gen).save(file_path_2)
|
19 |
-
time_2 = time.time()
|
20 |
-
save_time = time_2 - time_1
|
21 |
-
print(f"save_time:{save_time}")
|
22 |
-
time_1 = time.time()
|
23 |
-
handler = fal_client.submit(
|
24 |
-
"fal-ai/cat-vton",
|
25 |
-
arguments={
|
26 |
-
"human_image_url": fal_client.upload_file(file_path_1),
|
27 |
-
"garment_image_url": fal_client.upload_file(file_path_2),
|
28 |
-
"cloth_type": "overall"
|
29 |
-
},
|
30 |
-
)
|
31 |
-
request_id = handler.request_id
|
32 |
-
result = fal_client.result("fal-ai/cat-vton", request_id)
|
33 |
-
time_2 = time.time()
|
34 |
-
cat_time = time_2 - time_1
|
35 |
-
print(f"cat_time:{cat_time}")
|
36 |
-
time_1 = time.time()
|
37 |
-
response = requests.get(result['image']['url'])
|
38 |
-
time_2 = time.time()
|
39 |
-
url_time = time_2 - time_1
|
40 |
-
print(f"url_time:{url_time}")
|
41 |
-
time_1 = time.time()
|
42 |
-
save_directory = "downloads"
|
43 |
-
if response.status_code == 200:
|
44 |
-
filename = os.path.join(save_directory, f"cat-vton.png")
|
45 |
-
with open(filename, 'wb') as f:
|
46 |
-
f.write(response.content)
|
47 |
-
else:
|
48 |
-
print(f"Failed to download image from {result['image']['url']}")
|
49 |
-
time_2 = time.time()
|
50 |
-
downloads_time = time_2 - time_1
|
51 |
-
print(f"downloads_time:{downloads_time}")
|
52 |
-
return os.path.join(save_directory, f"cat-vton.png")
|
53 |
-
|
54 |
-
# user_dress("8950.jpg")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|