ishworrsubedii commited on
Commit
3d9be5f
·
1 Parent(s): b4a28c6

update: necklace placement bug fixed

Browse files
src/components/product_page_nto_cto_gen.py CHANGED
@@ -103,7 +103,7 @@ class ProductPageImageGeneration:
103
  print(f"Error in necklace try-on: {str(e)}")
104
  return None
105
 
106
- def process_clothing_tryon(self, image_path: str, clothing_type: str) -> dict:
107
  """Process a clothing try-on request"""
108
  try:
109
  with open(image_path, 'rb') as img_file:
@@ -116,7 +116,25 @@ class ProductPageImageGeneration:
116
  response = requests.post(self.cto_endpoint, files=files, data=data)
117
  response.raise_for_status()
118
  logger.info(f"Clothing Try on Completed for {clothing_type}")
119
- return response.json()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
 
121
  except Exception as e:
122
  logger.info(f"Error in clothing try-on: {str(e)}")
@@ -183,7 +201,7 @@ class ProductPageImageGeneration:
183
 
184
  # 2. Process each clothing type
185
  for clothing_type in clothing_list:
186
- cto_response = self.process_clothing_tryon(model_image_path, clothing_type)
187
 
188
  if cto_response and cto_response.get("code") == 200:
189
  try:
 
103
  print(f"Error in necklace try-on: {str(e)}")
104
  return None
105
 
106
+ def process_clothing_tryon(self, image_path: str, clothing_type: str, necklace_id: str, category: str, store_name: str, offset_x: float, offset_y: float) -> dict:
107
  """Process a clothing try-on request"""
108
  try:
109
  with open(image_path, 'rb') as img_file:
 
116
  response = requests.post(self.cto_endpoint, files=files, data=data)
117
  response.raise_for_status()
118
  logger.info(f"Clothing Try on Completed for {clothing_type}")
119
+ response=response.json()
120
+
121
+ output_url= requests.get(response['output'])
122
+ temp_path_cto=f"temp_{clothing_type}_cto.png"
123
+ with open(temp_path_cto, 'wb') as f:
124
+ f.write(output_url.content)
125
+
126
+ nto_outputs=self.process_necklace_tryon(
127
+ temp_path_cto,
128
+ necklace_id=necklace_id,
129
+ category=category,
130
+ store_name=store_name,
131
+ offset_x=offset_x,
132
+ offset_y=offset_y
133
+
134
+ )
135
+ os.remove(temp_path_cto)
136
+
137
+ return nto_outputs
138
 
139
  except Exception as e:
140
  logger.info(f"Error in clothing try-on: {str(e)}")
 
201
 
202
  # 2. Process each clothing type
203
  for clothing_type in clothing_list:
204
+ cto_response = self.process_clothing_tryon(model_image_path, clothing_type,necklace_id=necklace_config['id'], category=necklace_config['category'], store_name=necklace_config['store_name'], offset_x=necklace_config['offset_x'], offset_y=necklace_config['offset_y'])
205
 
206
  if cto_response and cto_response.get("code") == 200:
207
  try: