Update app.py
Browse files
app.py
CHANGED
|
@@ -114,7 +114,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"
|
|
@@ -129,6 +129,10 @@ def create_salesforce_record(score, checklist_summary, missing_summary, status,
|
|
| 129 |
summarized_checklist = summarize_text(checklist_summary)
|
| 130 |
summarized_missing = summarize_text(missing_summary)
|
| 131 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
# Ensure inputs are properly formatted
|
| 133 |
score = float(score) if score is not None else 0.0
|
| 134 |
checklist_summary = str(checklist_summary) if checklist_summary else ""
|
|
@@ -139,7 +143,6 @@ def create_salesforce_record(score, checklist_summary, missing_summary, status,
|
|
| 139 |
logs = str(logs) if logs else ""
|
| 140 |
qa_report = str(qa_report) if qa_report else ""
|
| 141 |
punch_list_text = str(punch_list_text) if punch_list_text else ""
|
| 142 |
-
project_id = str(project_id) if project_id else "" # Ensure project_id is a string
|
| 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 |
evaluated_at = datetime.now().strftime("%Y-%m-%dT%H:%M:%SZ") # Salesforce Date/Time format
|
|
@@ -392,7 +395,6 @@ with gr.Blocks(css="""
|
|
| 392 |
)
|
| 393 |
with gr.Row():
|
| 394 |
with gr.Column(scale=2):
|
| 395 |
-
project_id_input = gr.Textbox(label="Project ID", placeholder="Enter Project ID (e.g., PROJ-1234)")
|
| 396 |
logs_input = gr.Textbox(label="Project Logs", lines=5, placeholder="Enter project logs (e.g., 'Project complete, handover done')")
|
| 397 |
qa_input = gr.Dropdown(
|
| 398 |
label="QA Report",
|
|
@@ -436,7 +438,7 @@ with gr.Blocks(css="""
|
|
| 436 |
fn=create_salesforce_record,
|
| 437 |
inputs=[
|
| 438 |
score_output, checklist_output, missing_output, status_output,
|
| 439 |
-
gr.State(), gr.State(), gr.State(), gr.State(), open_punch_items_output, pdf_output
|
| 440 |
],
|
| 441 |
outputs=None
|
| 442 |
)
|
|
|
|
| 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"
|
|
|
|
| 129 |
summarized_checklist = summarize_text(checklist_summary)
|
| 130 |
summarized_missing = summarize_text(missing_summary)
|
| 131 |
|
| 132 |
+
# Generate Project ID based on timestamp
|
| 133 |
+
project_id = f"PROJ-{datetime.now().strftime('%Y%m%d-%H%M%S')}"
|
| 134 |
+
logging.info(f"Generated Project ID: {project_id}")
|
| 135 |
+
|
| 136 |
# Ensure inputs are properly formatted
|
| 137 |
score = float(score) if score is not None else 0.0
|
| 138 |
checklist_summary = str(checklist_summary) if checklist_summary else ""
|
|
|
|
| 143 |
logs = str(logs) if logs else ""
|
| 144 |
qa_report = str(qa_report) if qa_report else ""
|
| 145 |
punch_list_text = str(punch_list_text) if punch_list_text else ""
|
|
|
|
| 146 |
missing_documents = len(missing_summary.split(", ")) if missing_summary and missing_summary != "None" else 0
|
| 147 |
open_punch_items = int(open_punch_items) if open_punch_items is not None else 0
|
| 148 |
evaluated_at = datetime.now().strftime("%Y-%m-%dT%H:%M:%SZ") # Salesforce Date/Time format
|
|
|
|
| 395 |
)
|
| 396 |
with gr.Row():
|
| 397 |
with gr.Column(scale=2):
|
|
|
|
| 398 |
logs_input = gr.Textbox(label="Project Logs", lines=5, placeholder="Enter project logs (e.g., 'Project complete, handover done')")
|
| 399 |
qa_input = gr.Dropdown(
|
| 400 |
label="QA Report",
|
|
|
|
| 438 |
fn=create_salesforce_record,
|
| 439 |
inputs=[
|
| 440 |
score_output, checklist_output, missing_output, status_output,
|
| 441 |
+
gr.State(), gr.State(), gr.State(), gr.State(), open_punch_items_output, pdf_output
|
| 442 |
],
|
| 443 |
outputs=None
|
| 444 |
)
|