Strongich commited on
Commit
08066b1
·
1 Parent(s): f701a41

labels assignment to all products

Browse files
Files changed (1) hide show
  1. app.py +17 -22
app.py CHANGED
@@ -538,32 +538,27 @@ def render_html_page(chat_text, images_to_use):
538
  ]
539
  processed_links = [link for img in images_to_use for link in IMAGES[img]["links"]]
540
 
541
- # Counter for total labels
542
- total_labels_assigned = 0
543
- MAX_TOTAL_LABELS = 3 # Maximum number of labels allowed
544
-
545
  # Initialize labels for all products
546
  labels = [""] * len(processed_prices)
547
 
548
- # Assign "BEST VALUE!" to the lowest price
549
- if processed_prices:
550
- min_price_index = processed_prices.index(min(processed_prices))
 
 
 
 
 
 
551
  labels[min_price_index] = "<b>BEST VALUE</b>"
552
- total_labels_assigned += 1
553
-
554
- # Assign random labels to others
555
- other_indices = [i for i in range(len(processed_prices)) if i != min_price_index]
556
- random.shuffle(other_indices)
557
-
558
- for idx in other_indices:
559
- if total_labels_assigned < MAX_TOTAL_LABELS:
560
- label_choice = random.choice(
561
- ["<b>BEST QUALITY</b>", "<b>FAST PRODUCTION</b>"]
562
- )
563
- labels[idx] = label_choice
564
- total_labels_assigned += 1
565
- else:
566
- break
567
 
568
  # Generate HTML content
569
  for i in range(len(processed_images)):
 
538
  ]
539
  processed_links = [link for img in images_to_use for link in IMAGES[img]["links"]]
540
 
 
 
 
 
541
  # Initialize labels for all products
542
  labels = [""] * len(processed_prices)
543
 
544
+ # Group prices in subsets of 3 and assign labels
545
+ for group_start in range(0, len(processed_prices), 3):
546
+ subset_indices = list(
547
+ range(group_start, min(group_start + 3, len(processed_prices)))
548
+ )
549
+ subset_prices = [processed_prices[i] for i in subset_indices]
550
+
551
+ # Find the index of the lowest price in this subset
552
+ min_price_index = subset_indices[subset_prices.index(min(subset_prices))]
553
  labels[min_price_index] = "<b>BEST VALUE</b>"
554
+
555
+ # Assign remaining labels randomly
556
+ remaining_indices = [i for i in subset_indices if i != min_price_index]
557
+ random.shuffle(remaining_indices)
558
+ labels[remaining_indices[0]] = "<b>BEST QUALITY</b>"
559
+ labels[remaining_indices[1]] = (
560
+ "<b>FAST PRODUCTION</b>" if len(remaining_indices) > 1 else ""
561
+ )
 
 
 
 
 
 
 
562
 
563
  # Generate HTML content
564
  for i in range(len(processed_images)):