File size: 1,350 Bytes
f33a600
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import pandas as pd
from fuzzywuzzy import process

def predict_dimensions_from_annotations(annotations):
    # Load the data from CSV into a DataFrame
    data = pd.read_csv("/content/output.csv")

    # Initialize a list to store the predicted dimensions
    predicted_dimensions = []

    # Iterate over the annotations
    for annotation in annotations:
        # Extract object type name
        object_type_name = annotation['object_type_name']
        
        # Use fuzzy matching to find the closest matching product name in the CSV data
        closest_match = process.extractOne(object_type_name, data['Product Family'])
        
        # If a match is found above a certain threshold
        if closest_match[1] >= 50:
            # Get the index of the matched product family
            index = data[data['Product Family'] == closest_match[0]].index[0]
            
            # Retrieve the dimensions of the matched product
            length, height, width = data.loc[index, ['LENGTH (Inches)', 'HEIGHT (Inches)', 'WIDTH (Inches)']]
            
            # Append the predicted dimensions to the list
            predicted_dimensions.append((length, height, width))
        else:
            # If no match is found above the threshold, append None
            predicted_dimensions.append(None)

    return predicted_dimensions