Contract Document Information Extract and Store in Salesforce
Contract Document Information Extract and Store in Salesforce
Salesforce Opportunity
Objective:
<template>
<lightning-card title="Upload Contract">
<lightning-file-upload
label="Upload Contract File"
record-id={recordId}
accepted-formats={acceptedFormats}
onuploadfinished={handleUploadFinished}>
</lightning-file-upload>
<template if:true={isLoading}>
<lightning-spinner
alternative-text="Processing..."></lightning-spinner>
</template>
<template if:true={companyName}>
<p>Extracted Legal Company Name: {companyName}</p>
</template>
<template if:true={contractAmount}>
<p>Extracted Contract Amount: {contractAmount}</p>
</template>
</lightning-card>
</template>
handleUploadFinished(event) {
this.isLoading = true;
This Apex controller will handle sending the uploaded file to Google
Vertex AI and update the Opportunity with the extracted data.
if (res.getStatusCode() == 200) {
// Parse the response from Google Vertex AI
Map<String, Object> result = (Map<String, Object>)
JSON.deserializeUntyped(res.getBody());
return result;
} else {
throw new CustomException('Error processing contract: ' +
res.getBody());
}
}
}
import os
from google.cloud import storage
from google.cloud import aiplatform
# Call Vertex AI
response = prediction_client.predict(
endpoint=f'projects/{project_id}/locations/{location}/endpoints/{endp
oint}',
instances=payload['instances']
)
company_name = ''
contract_amount = ''
# Example usage:
if __name__ == "__main__":
file_path = "path_to_your_contract.pdf"
company_name, contract_amount =
extract_contract_fields(file_path)
print(f"Extracted Legal Company Name: {company_name}")
print(f"Extracted Contract Amount: {contract_amount}")
Conclusion