Zuii commited on
Commit
92dcd08
Β·
verified Β·
1 Parent(s): 813e34f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -16
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
- # 🎯 Convert image to RGB format (fixes blue tint!)
21
- def convert_to_rgb(image):
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
- # 🎲 Handle seed
53
  if random_seed:
54
  import random
55
  seed = random.randint(0, 1000000)
56
 
57
- # πŸ”₯ Convert images to RGB and normalize
58
- person_img = convert_to_rgb(person_img)
59
- cloth_img = convert_to_rgb(cloth_img)
60
 
61
- # βœ‚οΈ Resize to 256x256
62
  person_img = cv2.resize(person_img, (256, 256))
63
  cloth_img = cv2.resize(cloth_img, (256, 256))
64
 
65
- # 🎯 Simulate "Success" output (model processing should go here)
66
  output_img = person_img.copy()
67
 
68
- # πŸ”΅ **Blue Tint Fix: Ensure correct color space in final output**
69
- output_img = cv2.cvtColor(output_img, cv2.COLOR_BGR2RGB)
 
 
 
 
 
70
 
71
- return output_img, seed, "βœ… Success"
 
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 {