Dineshpopuri commited on
Commit
5fe047a
·
verified ·
1 Parent(s): 193525a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -6
app.py CHANGED
@@ -10,6 +10,7 @@ from retry import retry
10
  import time
11
  from datetime import datetime
12
  import base64
 
13
 
14
  # Print statement to confirm script initialization
15
  print("Starting Project Closure Readiness Evaluator app...")
@@ -114,7 +115,7 @@ def summarize_text(text, max_length=100, min_length=30):
114
  return text # Fallback to original text
115
 
116
  # Create Salesforce record in custom object Project_Closure_Handover__c
117
- def create_salesforce_record(score, checklist_summary, missing_summary, status, escalated, logs, qa_report, punch_list_text, open_punch_items, pdf_path=None):
118
  if not SALESFORCE_AVAILABLE:
119
  logging.error("Salesforce library not available. Skipping record creation.")
120
  return "Salesforce library not available"
@@ -141,13 +142,17 @@ def create_salesforce_record(score, checklist_summary, missing_summary, status,
141
  punch_list_text = str(punch_list_text) if punch_list_text else ""
142
  missing_documents = len(missing_summary.split(", ")) if missing_summary and missing_summary != "None" else 0
143
  open_punch_items = int(open_punch_items) if open_punch_items is not None else 0
144
- evaluated_at = datetime.now().strftime("%Y-%m-%dT%H:%M:%SZ") # Salesforce Date/Time format
 
 
 
145
  alert_sent = str(bool(escalated)).lower() # Converts True/False to "true"/"false"
146
  logging.info(f"Setting Alert_Sent__c to: {alert_sent}")
147
  escalation_flag = str(bool(escalated)).lower() # Ensure this is also a proper boolean string
148
 
149
  # Create the record in Project_Closure_Handover__c without the PDF URL for now
150
  record = {
 
151
  "Readiness_Score__c": score,
152
  "Checklist_Summary__c": checklist_summary,
153
  "Missing_Documents__c": missing_documents,
@@ -224,10 +229,10 @@ def sanitize_input(text):
224
  return bleach.clean(text.strip())
225
 
226
  # Rule-based completeness engine with weighted scoring
227
- def evaluate_readiness(logs, qa_report, punch_list_text):
228
  try:
229
  # Log inputs for debugging
230
- logging.info(f"Inputs - Logs: {logs}, QA Report: {qa_report}, Punch List: {punch_list_text}")
231
 
232
  # Initialize score and lists for tracking
233
  score = 0
@@ -240,6 +245,7 @@ def evaluate_readiness(logs, qa_report, punch_list_text):
240
  PUNCH_WEIGHT = 30 # 30% weight for punch list
241
 
242
  # Sanitize inputs
 
243
  logs = sanitize_input(logs)
244
  qa_report = sanitize_input(qa_report)
245
  punch_list_text = sanitize_input(punch_list_text)
@@ -390,6 +396,7 @@ with gr.Blocks(css="""
390
  )
391
  with gr.Row():
392
  with gr.Column(scale=2):
 
393
  logs_input = gr.Textbox(label="Project Logs", lines=5, placeholder="Enter project logs (e.g., 'Project complete, handover done')")
394
  qa_input = gr.Dropdown(
395
  label="QA Report",
@@ -420,7 +427,7 @@ with gr.Blocks(css="""
420
  # Chain the evaluation, PDF generation, and Salesforce record creation
421
  submit_btn.click(
422
  fn=evaluate_readiness,
423
- inputs=[logs_input, qa_input, punch_input],
424
  outputs=[
425
  score_output, checklist_output, missing_output, status_output, progress_output,
426
  gr.State(), gr.State(), gr.State(), gr.State(), open_punch_items_output, status_output
@@ -432,7 +439,7 @@ with gr.Blocks(css="""
432
  ).then(
433
  fn=create_salesforce_record,
434
  inputs=[
435
- score_output, checklist_output, missing_output, status_output,
436
  gr.State(), gr.State(), gr.State(), gr.State(), open_punch_items_output, pdf_output
437
  ],
438
  outputs=None
 
10
  import time
11
  from datetime import datetime
12
  import base64
13
+ import pytz # Added for proper timezone handling
14
 
15
  # Print statement to confirm script initialization
16
  print("Starting Project Closure Readiness Evaluator app...")
 
115
  return text # Fallback to original text
116
 
117
  # Create Salesforce record in custom object Project_Closure_Handover__c
118
+ def create_salesforce_record(project_id, score, checklist_summary, missing_summary, status, escalated, logs, qa_report, punch_list_text, open_punch_items, pdf_path=None):
119
  if not SALESFORCE_AVAILABLE:
120
  logging.error("Salesforce library not available. Skipping record creation.")
121
  return "Salesforce library not available"
 
142
  punch_list_text = str(punch_list_text) if punch_list_text else ""
143
  missing_documents = len(missing_summary.split(", ")) if missing_summary and missing_summary != "None" else 0
144
  open_punch_items = int(open_punch_items) if open_punch_items is not None else 0
145
+
146
+ # Set timezone to Asia/Kolkata (IST) and get current time
147
+ ist_tz = pytz.timezone("Asia/Kolkata")
148
+ evaluated_at = datetime.now(ist_tz).strftime("%Y-%m-%dT%H:%M:%SZ") # Salesforce Date/Time format in UTC with Z
149
  alert_sent = str(bool(escalated)).lower() # Converts True/False to "true"/"false"
150
  logging.info(f"Setting Alert_Sent__c to: {alert_sent}")
151
  escalation_flag = str(bool(escalated)).lower() # Ensure this is also a proper boolean string
152
 
153
  # Create the record in Project_Closure_Handover__c without the PDF URL for now
154
  record = {
155
+ "Project_ID__c": project_id, # Added Project ID field
156
  "Readiness_Score__c": score,
157
  "Checklist_Summary__c": checklist_summary,
158
  "Missing_Documents__c": missing_documents,
 
229
  return bleach.clean(text.strip())
230
 
231
  # Rule-based completeness engine with weighted scoring
232
+ def evaluate_readiness(project_id, logs, qa_report, punch_list_text):
233
  try:
234
  # Log inputs for debugging
235
+ logging.info(f"Inputs - Project ID: {project_id}, Logs: {logs}, QA Report: {qa_report}, Punch List: {punch_list_text}")
236
 
237
  # Initialize score and lists for tracking
238
  score = 0
 
245
  PUNCH_WEIGHT = 30 # 30% weight for punch list
246
 
247
  # Sanitize inputs
248
+ project_id = sanitize_input(project_id)
249
  logs = sanitize_input(logs)
250
  qa_report = sanitize_input(qa_report)
251
  punch_list_text = sanitize_input(punch_list_text)
 
396
  )
397
  with gr.Row():
398
  with gr.Column(scale=2):
399
+ project_id_input = gr.Textbox(label="Project ID", placeholder="Enter Project ID (e.g., PROJ-12345)") # Added Project ID input
400
  logs_input = gr.Textbox(label="Project Logs", lines=5, placeholder="Enter project logs (e.g., 'Project complete, handover done')")
401
  qa_input = gr.Dropdown(
402
  label="QA Report",
 
427
  # Chain the evaluation, PDF generation, and Salesforce record creation
428
  submit_btn.click(
429
  fn=evaluate_readiness,
430
+ inputs=[project_id_input, logs_input, qa_input, punch_input],
431
  outputs=[
432
  score_output, checklist_output, missing_output, status_output, progress_output,
433
  gr.State(), gr.State(), gr.State(), gr.State(), open_punch_items_output, status_output
 
439
  ).then(
440
  fn=create_salesforce_record,
441
  inputs=[
442
+ project_id_input, score_output, checklist_output, missing_output, status_output,
443
  gr.State(), gr.State(), gr.State(), gr.State(), open_punch_items_output, pdf_output
444
  ],
445
  outputs=None