pavansuresh commited on
Commit
061b9a2
·
verified ·
1 Parent(s): 3f4738a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -10
app.py CHANGED
@@ -13,21 +13,32 @@ def process_contract(pdf_file, object_name):
13
  try:
14
  token, instance_url = get_token()
15
  except Exception as e:
16
- return f"❌ {str(e)}", None
17
 
18
  # Step 1: OCR
19
- text_data = extract_text_from_pdf(pdf_file.name) # ✅ FIXED: use .name to get file path
 
 
 
 
 
20
 
21
  # Step 2: AI Mapping
22
- mappings = run_ai_mapping(text_data)
 
 
 
23
 
24
  # Step 3: Create Salesforce record
25
- record_response = create_record(object_name, mappings, token, instance_url)
26
- if 'id' in record_response:
27
- attach_pdf(record_response['id'], pdf_file.name, token, instance_url)
28
- return f"✅ Record created: {record_response['id']}", mappings
29
- else:
30
- return f"❌ Failed to create record: {record_response}", mappings
 
 
 
31
 
32
  def get_salesforce_object_names():
33
  try:
@@ -35,7 +46,7 @@ def get_salesforce_object_names():
35
  objects = get_salesforce_objects(token, instance_url)
36
  return [obj['name'] for obj in objects if obj.get('createable')]
37
  except Exception as e:
38
- return [f"❌ {str(e)}"]
39
 
40
  with gr.Blocks() as demo:
41
  gr.Markdown("## 📄 Smart Contract Migrator (Gradio)")
 
13
  try:
14
  token, instance_url = get_token()
15
  except Exception as e:
16
+ return f"❌ Salesforce authentication failed: {str(e)}", None
17
 
18
  # Step 1: OCR
19
+ try:
20
+ text_data = extract_text_from_pdf(pdf_file.name) # Use .name to get file path
21
+ if not text_data:
22
+ return "⚠️ No text extracted from PDF. It may be empty or require OCR.", None
23
+ except Exception as e:
24
+ return f"❌ Failed to extract text from PDF: {str(e)}", None
25
 
26
  # Step 2: AI Mapping
27
+ try:
28
+ mappings = run_ai_mapping(text_data)
29
+ except Exception as e:
30
+ return f"❌ AI mapping failed: {str(e)}", None
31
 
32
  # Step 3: Create Salesforce record
33
+ try:
34
+ record_response = create_record(object_name, mappings, token, instance_url)
35
+ if 'id' in record_response:
36
+ attach_pdf(record_response['id'], pdf_file.name, token, instance_url)
37
+ return f"✅ Record created: {record_response['id']}", mappings
38
+ else:
39
+ return f"❌ Failed to create record: {record_response}", mappings
40
+ except Exception as e:
41
+ return f"❌ Failed to create Salesforce record: {str(e)}", mappings
42
 
43
  def get_salesforce_object_names():
44
  try:
 
46
  objects = get_salesforce_objects(token, instance_url)
47
  return [obj['name'] for obj in objects if obj.get('createable')]
48
  except Exception as e:
49
+ return [f"❌ Failed to fetch Salesforce objects: {str(e)}"]
50
 
51
  with gr.Blocks() as demo:
52
  gr.Markdown("## 📄 Smart Contract Migrator (Gradio)")