dschandra commited on
Commit
f8912a5
Β·
verified Β·
1 Parent(s): 72911c7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -15
app.py CHANGED
@@ -15,12 +15,11 @@ SF_PASSWORD = os.getenv("SF_PASSWORD")
15
  SF_SECURITY_TOKEN = os.getenv("SF_SECURITY_TOKEN")
16
  SF_LOGIN_URL = os.getenv("SF_LOGIN_URL", "https://login.salesforce.com")
17
  SF_OBJECT_NAME = os.getenv("SF_OBJECT_NAME", "Agent_Prospect__c")
18
- SF_SCORE_FIELD = os.getenv("SF_SCORE_FIELD", "Suitability_Srode__c")
19
  SF_LINK_FIELD = os.getenv("SF_RESUME_FIELD_LINK", "Resume_File_Link__c")
20
- SF_RECORD_ID = os.getenv("SF_RECORD_ID")
21
 
22
  # Validate required credentials
23
- required = ["SF_USERNAME", "SF_PASSWORD", "SF_SECURITY_TOKEN", "SF_RECORD_ID"]
24
  missing = [var for var in required if not os.getenv(var)]
25
  if missing:
26
  raise ValueError(f"Missing required .env variables: {', '.join(missing)}")
@@ -46,9 +45,6 @@ classifier = pipeline("text-classification", model="nlptown/bert-base-multilingu
46
 
47
  def process_resume(file):
48
  try:
49
- record_id = SF_RECORD_ID
50
- print(f"Processing resume for record ID: {record_id}")
51
-
52
  # Extract text from PDF
53
  with pdfplumber.open(file.name) as pdf:
54
  extracted_text = "\n".join([page.extract_text() or "" for page in pdf.pages])
@@ -88,7 +84,19 @@ def process_resume(file):
88
  content_doc_id = query_result["records"][0]["ContentDocumentId"]
89
  print(f"ContentDocumentId: {content_doc_id}")
90
 
91
- # Link file to Salesforce record
 
 
 
 
 
 
 
 
 
 
 
 
92
  try:
93
  sf.ContentDocumentLink.create({
94
  "ContentDocumentId": content_doc_id,
@@ -105,14 +113,17 @@ def process_resume(file):
105
  download_link = f"https://{sf.sf_instance}/sfc/servlet.shepherd/document/download/{content_doc_id}"
106
  print(f"Download link: {download_link}")
107
 
108
- # Update record with score and link
109
- sf.__getattr__(SF_OBJECT_NAME).update(record_id, {
110
- SF_SCORE_FIELD: score,
111
- SF_LINK_FIELD: download_link
112
- })
113
- print("Salesforce record updated successfully.")
 
 
 
114
 
115
- return f"{summary}\n\nβœ… Score and resume uploaded to Salesforce.\nπŸ“Ž [Download Resume]({download_link})"
116
 
117
  except Exception as e:
118
  return f"❌ Error: {str(e)}"
@@ -123,5 +134,5 @@ gr.Interface(
123
  inputs=gr.File(label="Upload Resume (PDF)", file_types=[".pdf"]),
124
  outputs="text",
125
  title="LIC Resume AI Scorer",
126
- description="Upload a resume PDF. It will be scored and stored in Salesforce automatically."
127
  ).launch(share=False)
 
15
  SF_SECURITY_TOKEN = os.getenv("SF_SECURITY_TOKEN")
16
  SF_LOGIN_URL = os.getenv("SF_LOGIN_URL", "https://login.salesforce.com")
17
  SF_OBJECT_NAME = os.getenv("SF_OBJECT_NAME", "Agent_Prospect__c")
18
+ SF_SCORE_FIELD = os.getenv("SF_SCORE_FIELD", "Suitability_Score__c")
19
  SF_LINK_FIELD = os.getenv("SF_RESUME_FIELD_LINK", "Resume_File_Link__c")
 
20
 
21
  # Validate required credentials
22
+ required = ["SF_USERNAME", "SF_PASSWORD", "SF_SECURITY_TOKEN"]
23
  missing = [var for var in required if not os.getenv(var)]
24
  if missing:
25
  raise ValueError(f"Missing required .env variables: {', '.join(missing)}")
 
45
 
46
  def process_resume(file):
47
  try:
 
 
 
48
  # Extract text from PDF
49
  with pdfplumber.open(file.name) as pdf:
50
  extracted_text = "\n".join([page.extract_text() or "" for page in pdf.pages])
 
84
  content_doc_id = query_result["records"][0]["ContentDocumentId"]
85
  print(f"ContentDocumentId: {content_doc_id}")
86
 
87
+ # Create a new Agent_Prospect__c record
88
+ try:
89
+ record_result = sf.__getattr__(SF_OBJECT_NAME).create({
90
+ SF_SCORE_FIELD: score,
91
+ SF_LINK_FIELD: "" # Placeholder; will update with download link
92
+ })
93
+ record_id = record_result.get("id")
94
+ print(f"New Agent_Prospect__c record created: {record_id}")
95
+ except Exception as e:
96
+ print(f"Error creating Agent_Prospect__c record: {str(e)}")
97
+ raise
98
+
99
+ # Link file to the new Salesforce record
100
  try:
101
  sf.ContentDocumentLink.create({
102
  "ContentDocumentId": content_doc_id,
 
113
  download_link = f"https://{sf.sf_instance}/sfc/servlet.shepherd/document/download/{content_doc_id}"
114
  print(f"Download link: {download_link}")
115
 
116
+ # Update the record with the download link
117
+ try:
118
+ sf.__getattr__(SF_OBJECT_NAME).update(record_id, {
119
+ SF_LINK_FIELD: download_link
120
+ })
121
+ print("Salesforce record updated with download link.")
122
+ except Exception as e:
123
+ print(f"Error updating record with download link: {str(e)}")
124
+ raise
125
 
126
+ return f"{summary}\n\nβœ… New record created and resume uploaded to Salesforce.\nπŸ“Ž [Download Resume]({download_link})\nRecord ID: {record_id}"
127
 
128
  except Exception as e:
129
  return f"❌ Error: {str(e)}"
 
134
  inputs=gr.File(label="Upload Resume (PDF)", file_types=[".pdf"]),
135
  outputs="text",
136
  title="LIC Resume AI Scorer",
137
+ description="Upload a resume PDF. A new record will be created in Salesforce with the score and resume."
138
  ).launch(share=False)