Spaces:
Build error
Build error
Update app.py
Browse files177 unmodified lines178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207177 unmodified lines# Extract attributes from the extracted textattributes = extract_attributes(extracted_text)# Explicitly extract Product Name from the attributesproduct_name = attributes.get("Productname", "").strip() # Extract 'Productname' from the textif product_name:# Ensure that the Product Name is mapped to the right Salesforce fieldif entry_type == "Sales":attributes["Product_Name__c"] = product_name # For VENKATA_RAMANA_MOTORS__celif entry_type == "Non-Sales":attributes["Productname__c"] = product_name # For UNBILLING_DATA__c# Convert extracted keys to match Salesforce API field namesmapped_attributes = {}for key, value in attributes.items():field_name_sf = key.replace(" ", "_") + "__c" # Convert to Salesforce formatif field_name_sf in valid_fields:mapped_attributes[field_name_sf] = value # Only keep valid fieldsmapped_attributes[field_name] = quantity # Ensure Quantity is addedif not mapped_attributes:return "No valid attributes found to export."# Creating a new record with all valid attributessf_object.create(mapped_attributes)return f"✅ Record created in {object_name} with extracted valid attributes and Quantity: {quantity}."elif mode == "Exit":if entry_type == "Sales":177 unmodified lines178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215177 unmodified lines# Extract attributes from the extracted textattributes = extract_attributes(extracted_text)# Ensure Product Name is extracted and mapped correctlyproduct_name = match_product_name(extracted_text) # Match product name using fuzzy logicif not product_name:return "❌ Product Name could not be extracted from the image. Please check the image."# Assign Product Name to the correct Salesforce fieldif entry_type == "Sales":attributes["Product_Name__c"] = product_name # For VENKATA_RAMANA_MOTORS__celif entry_type == "Non-Sales":attributes["Productname__c"] = product_name # For UNBILLING_DATA__c# Convert extracted keys to match Salesforce API field namesmapped_attributes = {}for key, value in attributes.items():sf_field_name = ATTRIBUTE_MAPPING.get(key, key.replace(" ", "_") + "__c") # Convert to Salesforce formatif sf_field_name in valid_fields:mapped_attributes[sf_field_name] = value # Only keep valid fields# Ensure Product Name and Quantity are added to mapped attributesmapped_attributes["Product_Name__c"] = product_name # Product Name fieldmapped_attributes[field_name] = quantity # Quantity field# Ensure at least one valid field existsif not mapped_attributes:return "❌ No valid attributes found to export."# Creating a new record with all valid attributessf_object.create(mapped_attributes)return f"✅ Record created in {object_name} with extracted valid attributes, Product Name: {product_name}, and Quantity: {quantity}."except Exception as e:return f"❌ Error interacting with Salesforce: {str(e)}"elif mode == "Exit":if entry_type == "Sales":
app.py+25-17