File size: 1,499 Bytes
f8c0ae2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from unique_product_mapping import product_to_category, goal_format


def get_recommendations(selected_item, goal_format):
    # Find the class/category of the selected item
    selected_class_dict = product_to_category.get(selected_item, None)

    if selected_class_dict is None:
        print("Product not found.")
        return None, []

    selected_class = selected_class_dict.get('category', None)
    if not selected_class:
        print("Category not found for the selected product.")
        return None, []

    print(f"Selected Category: {selected_class}")

    # Filter all products in the same class/category
    same_class_products = goal_format.get(selected_class, [])

    # Remove the selected item itself from the list of recommendations (optional)
    if selected_item in same_class_products:
        same_class_products.remove(selected_item)

    # Prepare a list of recommendations with their image paths
    recommendations_with_images = [
        {"product": product, "image": product_to_category.get(product, {}).get('image', 'No image available')}
        for product in same_class_products
    ]

    return selected_class, recommendations_with_images


def cat_recc(selected_item):
    category, recommendations = get_recommendations(selected_item, goal_format)
    print(f"Selected Item: {selected_item}")
    print("Recommended:")
    for recommendation in recommendations:
        print(f"Product: {recommendation['product']}, Image Path: {recommendation['image']}")