Not-Adam commited on
Commit
f55e82b
1 Parent(s): b5ae5fa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -4
app.py CHANGED
@@ -50,10 +50,11 @@ OPENAI_USER_PROMPT = "I have a product called 'Round Neck Knitted Ribbed Crop To
50
  def shot(input, category, level):
51
  output_dict = {}
52
  if level == 'variant':
53
- subColour, mainColour, score = get_colour(ast.literal_eval(str(input)), category)
54
  openai_parsed_response = get_openAI_tags(ast.literal_eval(str(input)))
55
  face_embeddings = get_face_embeddings(ast.literal_eval(str(input)))
56
- cropped_images = get_cropped_images(ast.literal_eval(str(input)), category)
 
 
57
 
58
  # Ensure all outputs are JSON serializable
59
  output_dict['colors'] = {
@@ -623,7 +624,7 @@ def encode_images_to_base64(cropped_list):
623
 
624
  def get_cropped_images(images, category):
625
  cropped_list = []
626
- resultsPerCategory = {}
627
  for num, image in enumerate(images):
628
  try:
629
  image = open_image_from_url(image)
@@ -634,14 +635,20 @@ def get_cropped_images(images, category):
634
 
635
  for i, image in enumerate(cropped_images):
636
  cropped_list.append(image)
 
 
 
 
 
637
  except Exception as e:
638
  print(f"Error processing image {num}: {e}")
639
  return []
640
 
641
  # Convert cropped images to base64 strings
642
  base64_images = encode_images_to_base64(cropped_list)
 
643
 
644
- return base64_images
645
 
646
 
647
 
 
50
  def shot(input, category, level):
51
  output_dict = {}
52
  if level == 'variant':
 
53
  openai_parsed_response = get_openAI_tags(ast.literal_eval(str(input)))
54
  face_embeddings = get_face_embeddings(ast.literal_eval(str(input)))
55
+ cropped_images, product_crops = get_cropped_images(ast.literal_eval(str(input)), category)
56
+ print(product_crops)
57
+ subColour, mainColour, score = get_colour(product_crops, category)
58
 
59
  # Ensure all outputs are JSON serializable
60
  output_dict['colors'] = {
 
624
 
625
  def get_cropped_images(images, category):
626
  cropped_list = []
627
+ product_crops = []
628
  for num, image in enumerate(images):
629
  try:
630
  image = open_image_from_url(image)
 
635
 
636
  for i, image in enumerate(cropped_images):
637
  cropped_list.append(image)
638
+
639
+ # If the detected class is the same as the category, add the image to the product crops
640
+ if cropped_classes[i] == get_category_index(category):
641
+ product_crops.append(image)
642
+
643
  except Exception as e:
644
  print(f"Error processing image {num}: {e}")
645
  return []
646
 
647
  # Convert cropped images to base64 strings
648
  base64_images = encode_images_to_base64(cropped_list)
649
+ product_base64_images = encode_images_to_base64(product_crops)
650
 
651
+ return base64_images, product_base64_images
652
 
653
 
654