Spaces:
Configuration error
Configuration error
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 | |