BinduRP commited on
Commit
32ae303
·
verified ·
1 Parent(s): ee0022d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -12
app.py CHANGED
@@ -50,32 +50,69 @@ df_merged = df_account.merge(df_credit, on="ID").merge(df_gov, on="ID", how="lef
50
  risk_policy = client.files.upload(file="Bank Loan Overall Risk Policy.pdf")
51
  rate_policy = client.files.upload(file="Bank Loan Interest Rate Policy.pdf")
52
 
53
- def process_loan(applicant_id, optional_name):
 
54
  try:
 
55
  row = df_merged[df_merged['ID'] == int(applicant_id)]
56
- if row.empty: return "ID not found."
57
  applicant = row.iloc[0]
58
 
 
59
  prompt = f"""
60
- Assess this loan application using the provided PDF policies:
61
- Name: {applicant['Name']} (ID: {applicant_id}), Score: {applicant['Credit_Score']}, Status: {applicant['Status']}
62
- Nationality: {applicant['Nationality']}, PR Status: {applicant['PR_Status']}
63
-
64
- Follow the multi-step report format:
65
- 1. Info retrieval 2. PR check 3. Risk Assessment 4. Interest Rate 5. Recommendation
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  """
67
 
68
- # Using direct file objects in the contents list
69
  response = client.models.generate_content(
70
  model=STABLE_MODEL,
71
- contents=[risk_policy, rate_policy, prompt]
72
  )
73
  return response.text
74
 
75
  except exceptions.ResourceExhausted:
76
- return "Free tier limit reached. Please wait 60 seconds."
77
  except Exception as e:
78
- return f"Error: {str(e)}"
79
 
80
  # --- Gradio Interface ---
81
  demo = gr.Interface(
 
50
  risk_policy = client.files.upload(file="Bank Loan Overall Risk Policy.pdf")
51
  rate_policy = client.files.upload(file="Bank Loan Interest Rate Policy.pdf")
52
 
53
+ # 4. Standardized Assessment Logic
54
+ def process_loan_request(applicant_id, customer_name_optional):
55
  try:
56
+ # Retrieve data from the structured systems
57
  row = df_merged[df_merged['ID'] == int(applicant_id)]
58
+ if row.empty: return "Error: Applicant ID not found."
59
  applicant = row.iloc[0]
60
 
61
+ # THE STANDARDIZED PROMPT: Ensuring strict adherence to provided tables
62
  prompt = f"""
63
+ You are a Senior Loan Officer. Assess the application for the individual provided.
64
+ Stick strictly to the information and tables provided in the attached PDF policies.
65
+
66
+ APPLICANT DATA:
67
+ Name: {applicant['Name']}
68
+ ID: {applicant_id}
69
+ Credit Score: {applicant['Credit_Score']}
70
+ Account Status: {applicant['Status']}
71
+ Nationality: {applicant['Nationality']}
72
+ PR Status: {applicant['PR_Status']}
73
+
74
+ REQUIRED OUTPUT PATTERN:
75
+
76
+ # Loan Assessment Report: {applicant['Name']} (ID: {applicant_id})
77
+
78
+ ### **1. Info Retrieval**
79
+ | Applicant Detail | Value |
80
+ | :--- | :--- |
81
+ | Name (ID) | {applicant['Name']} ({applicant_id}) |
82
+ | Credit Score | {applicant['Credit_Score']} |
83
+ | Account Status | {applicant['Status']} |
84
+ | Nationality | {applicant['Nationality']} |
85
+ | PR Status | {applicant['PR_Status']} |
86
+
87
+ ### **2. PR Status Check**
88
+ - For Non-Singaporean applicants: State result as "PR Status -> [True/False]".
89
+ - For Singaporean applicants: State "Check not required for Singaporean".
90
+
91
+ ### **3. Overall Risk Assessment**
92
+ - Reference 'Bank Loan Overall Risk Policy.pdf'.
93
+ - Calculation: Credit Score [{applicant['Credit_Score']}] + Account Status [{applicant['Status']}] -> Overall Risk: [Value from Table]
94
+
95
+ ### **4. Interest Rate Determination**
96
+ - Reference 'Bank Loan Interest Rate Policy.pdf'.
97
+ - Calculation: Overall Risk [Value from Table] -> [Rate from Table]
98
+ - Apply conservative rule if risk falls between categories.
99
+
100
+ ### **5. Final Report & Recommendation**
101
+ - Recommend the loan interest rate OR Not recommend.
102
+ - Rationale: Based on risk profile and compliance (PR false for Non-Singaporean leads to 'Not recommend').
103
  """
104
 
105
+ # Generate content using the multimodal input
106
  response = client.models.generate_content(
107
  model=STABLE_MODEL,
108
+ contents=[risk_policy_file, interest_policy_file, prompt]
109
  )
110
  return response.text
111
 
112
  except exceptions.ResourceExhausted:
113
+ return "Error: Quota reached. Please wait 60 seconds."
114
  except Exception as e:
115
+ return f"System Error: {str(e)}"
116
 
117
  # --- Gradio Interface ---
118
  demo = gr.Interface(