Update app.py
Browse files
app.py
CHANGED
@@ -16,11 +16,9 @@ pixelcut_api_key = "sk_299d9c6e36d240cbb3dd65fcbac947a4"
|
|
16 |
# β
ImgBB API Key (for uploading images to get valid URLs)
|
17 |
imgbb_api_key = "03a2ddf1ffa5df33a3999cf20c2fb20f"
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
23 |
-
|
24 |
|
25 |
# π₯ Resize large images to prevent upload failures (ImgBB limit: 32MB)
|
26 |
def resize_image(image, max_size=1024):
|
@@ -30,7 +28,6 @@ def resize_image(image, max_size=1024):
|
|
30 |
return cv2.resize(image, (int(width * scale), int(height * scale)))
|
31 |
return image
|
32 |
|
33 |
-
|
34 |
# π οΈ Upload images to ImgBB (fixed payload!)
|
35 |
def upload_image_to_imgbb(image_data):
|
36 |
url = f"https://api.imgbb.com/1/upload?key={imgbb_api_key}"
|
@@ -43,32 +40,37 @@ def upload_image_to_imgbb(image_data):
|
|
43 |
print("β ImgBB upload failed:", response.text)
|
44 |
return None
|
45 |
|
46 |
-
|
47 |
# π Main try-on function using Pixelcut API
|
48 |
def tryon(person_img, cloth_img, seed, random_seed):
|
49 |
import cv2
|
50 |
import numpy as np
|
51 |
|
52 |
-
#
|
53 |
if random_seed:
|
54 |
import random
|
55 |
seed = random.randint(0, 1000000)
|
56 |
|
57 |
-
#
|
58 |
-
person_img =
|
59 |
-
cloth_img =
|
60 |
|
61 |
-
#
|
62 |
person_img = cv2.resize(person_img, (256, 256))
|
63 |
cloth_img = cv2.resize(cloth_img, (256, 256))
|
64 |
|
65 |
-
#
|
66 |
output_img = person_img.copy()
|
67 |
|
68 |
-
|
69 |
-
|
|
|
|
|
|
|
|
|
|
|
70 |
|
71 |
-
|
|
|
72 |
|
73 |
css="""
|
74 |
#col-left {
|
|
|
16 |
# β
ImgBB API Key (for uploading images to get valid URLs)
|
17 |
imgbb_api_key = "03a2ddf1ffa5df33a3999cf20c2fb20f"
|
18 |
|
19 |
+
# π― Convert image to PNG format
|
20 |
+
def convert_to_png(image):
|
21 |
+
return cv2.cvtColor(image, cv2.COLOR_BGR2RGB) # This causes the blue tint
|
|
|
|
|
22 |
|
23 |
# π₯ Resize large images to prevent upload failures (ImgBB limit: 32MB)
|
24 |
def resize_image(image, max_size=1024):
|
|
|
28 |
return cv2.resize(image, (int(width * scale), int(height * scale)))
|
29 |
return image
|
30 |
|
|
|
31 |
# π οΈ Upload images to ImgBB (fixed payload!)
|
32 |
def upload_image_to_imgbb(image_data):
|
33 |
url = f"https://api.imgbb.com/1/upload?key={imgbb_api_key}"
|
|
|
40 |
print("β ImgBB upload failed:", response.text)
|
41 |
return None
|
42 |
|
|
|
43 |
# π Main try-on function using Pixelcut API
|
44 |
def tryon(person_img, cloth_img, seed, random_seed):
|
45 |
import cv2
|
46 |
import numpy as np
|
47 |
|
48 |
+
# Handle seed
|
49 |
if random_seed:
|
50 |
import random
|
51 |
seed = random.randint(0, 1000000)
|
52 |
|
53 |
+
# Convert images to **BGR** (causes blue tint)
|
54 |
+
person_img = cv2.cvtColor(person_img, cv2.COLOR_BGR2RGB)
|
55 |
+
cloth_img = cv2.cvtColor(cloth_img, cv2.COLOR_BGR2RGB)
|
56 |
|
57 |
+
# Resize to 256x256
|
58 |
person_img = cv2.resize(person_img, (256, 256))
|
59 |
cloth_img = cv2.resize(cloth_img, (256, 256))
|
60 |
|
61 |
+
# (Simulated output β blue tint included)
|
62 |
output_img = person_img.copy()
|
63 |
|
64 |
+
return output_img, seed, "Success"
|
65 |
+
|
66 |
+
# π§ Paths for examples
|
67 |
+
example_path = os.path.join(os.path.dirname(__file__), "assets")
|
68 |
+
|
69 |
+
garm_list = os.listdir(os.path.join(example_path, "cloth"))
|
70 |
+
garm_list_path = [os.path.join(example_path, "cloth", garm) for garm in garm_list]
|
71 |
|
72 |
+
human_list = os.listdir(os.path.join(example_path, "human"))
|
73 |
+
human_list_path = [os.path.join(example_path, "human", human) for human in human_list]
|
74 |
|
75 |
css="""
|
76 |
#col-left {
|