Spaces:
Build error
Build error
Update app.py
Browse files177 unmodified lines178179180181182183184185186187188189190181182183184185186187188189190191192193194193194195195196197198199200197201202203204200205206202207208204209210211212213214215177 unmodified lines # Extract attributes from the extracted text attributes = extract_attributes(extracted_text)
# Explicitly extract Product Name from the attributes product_name = attributes.get("Productname", "").strip() # Extract 'Productname' from the text if product_name: # Ensure that the Product Name is mapped to the right Salesforce field if entry_type == "Sales": attributes["Product_Name__c"] = product_name # For VENKATA_RAMANA_MOTORS__c elif entry_type == "Non-Sales": attributes["Productname__c"] = product_name # For UNBILLING_DATA__c # Convert extracted keys to match Salesforce API field names # Ensure Product Name is extracted and mapped correctly product_name = match_product_name(extracted_text) # Match product name using fuzzy logic if not product_name: return "❌ Product Name could not be extracted from the image. Please check the image."
# Assign Product Name to the correct Salesforce field if entry_type == "Sales": attributes["Product_Name__c"] = product_name # For VENKATA_RAMANA_MOTORS__c elif entry_type == "Non-Sales": attributes["Productname__c"] = product_name # For UNBILLING_DATA__c
# Convert extracted keys to match Salesforce API field names mapped_attributes = {} for key, value in attributes.items(): field_name_sf = key.replace(" ", "_") + "__c" # Convert to Salesforce format if field_name_sf in valid_fields: mapped_attributes[field_name_sf] = value # Only keep valid fields sf_field_name = ATTRIBUTE_MAPPING.get(key, key.replace(" ", "_") + "__c") # Convert to Salesforce format if 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 attributes mapped_attributes["Product_Name__c"] = product_name # Product Name field mapped_attributes[field_name] = quantity # Ensure Quantity is added mapped_attributes[field_name] = quantity # Quantity field
# Ensure at least one valid field exists if not mapped_attributes: return "No valid attributes found to export." return "❌ No valid attributes found to export."
# Creating a new record with all valid attributes # Creating a new record with all valid attributes sf_object.create(mapped_attributes) return f"✅ Record created in {object_name} with extracted valid attributes and Quantity: {quantity}." 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