PPSharks commited on
Commit
4c2d5bb
1 Parent(s): bcdbbac

Upload user_dress.py

Browse files
Files changed (1) hide show
  1. user_dress.py +84 -82
user_dress.py CHANGED
@@ -1,82 +1,84 @@
1
- from io import BytesIO
2
- import fal_client
3
- import os
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()
15
- filename_1 = 'user_image.jpg'
16
- filename_2 = 'cloth_image.jpg'
17
- file_path_1 = os.path.join(UPLOAD_FOLDER, filename_1)
18
- file_path_2 = os.path.join(UPLOAD_FOLDER, filename_2)
19
- Image.fromarray(user_pic).save(file_path_1)
20
- Image.fromarray(cloth_gen).save(file_path_2)
21
- time_2 = time.time()
22
- save_time = time_2 - time_1
23
- print(f"save_time:{save_time}")
24
- time_1 = time.time()
25
- handler = fal_client.submit(
26
- "fal-ai/cat-vton",
27
- arguments={
28
- "human_image_url": fal_client.upload_file(file_path_1),
29
- "garment_image_url": fal_client.upload_file(file_path_2),
30
- "cloth_type": "overall"
31
- },
32
- )
33
- request_id = handler.request_id
34
- result = fal_client.result("fal-ai/cat-vton", request_id)
35
- time_2 = time.time()
36
- cat_time = time_2 - time_1
37
- print(f"cat_time:{cat_time}")
38
- time_1 = time.time()
39
- response = requests.get(result['image']['url'])
40
- time_2 = 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:
48
- f.write(response.content)
49
- else:
50
- print(f"Failed to download image from {result['image']['url']}")
51
- time_2 = time.time()
52
- downloads_time = time_2 - time_1
53
- print(f"downloads_time:{downloads_time}")
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'
61
- file_path_1 = os.path.join(UPLOAD_FOLDER, filename_1)
62
- file_path_2 = os.path.join(UPLOAD_FOLDER, filename_2)
63
- Image.fromarray(user_pic).save(file_path_1)
64
- Image.fromarray(cloth_gen).save(file_path_2)
65
- time_2 = time.time()
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
 
 
 
1
+ from io import BytesIO
2
+ import fal_client
3
+ import os
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()
15
+ filename_1 = 'user_image.jpg'
16
+ filename_2 = 'cloth_image.jpg'
17
+ file_path_1 = os.path.join(UPLOAD_FOLDER, filename_1)
18
+ file_path_2 = os.path.join(UPLOAD_FOLDER, filename_2)
19
+ Image.fromarray(user_pic).save(file_path_1)
20
+ Image.fromarray(cloth_gen).save(file_path_2)
21
+ time_2 = time.time()
22
+ save_time = time_2 - time_1
23
+ print(f"save_time:{save_time}")
24
+ time_1 = time.time()
25
+ handler = fal_client.submit(
26
+ "fal-ai/cat-vton",
27
+ arguments={
28
+ "human_image_url": fal_client.upload_file(file_path_1),
29
+ "garment_image_url": fal_client.upload_file(file_path_2),
30
+ "cloth_type": "overall"
31
+ },
32
+ )
33
+ request_id = handler.request_id
34
+ result = fal_client.result("fal-ai/cat-vton", request_id)
35
+ time_2 = time.time()
36
+ cat_time = time_2 - time_1
37
+ print(f"cat_time:{cat_time}")
38
+ time_1 = time.time()
39
+ response = requests.get(result['image']['url'])
40
+ time_2 = 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:
48
+ f.write(response.content)
49
+ else:
50
+ print(f"Failed to download image from {result['image']['url']}")
51
+ time_2 = time.time()
52
+ downloads_time = time_2 - time_1
53
+ print(f"downloads_time:{downloads_time}")
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'
61
+ file_path_1 = os.path.join(UPLOAD_FOLDER, filename_1)
62
+ file_path_2 = os.path.join(UPLOAD_FOLDER, filename_2)
63
+ Image.fromarray(user_pic).save(file_path_1)
64
+ Image.fromarray(cloth_gen).save(file_path_2)
65
+ time_2 = time.time()
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
+ user_dress_kolor(user_pic, cloth_gen, 4)#ddd
83
+ user_cloth.append(os.path.join(save_directory, f"kolor/kolor_4.png"))
84
+ return user_cloth