Update app.py
Browse files
app.py
CHANGED
|
@@ -29,7 +29,8 @@ def init_salesforce():
|
|
| 29 |
def create_salesforce_record(score, checklist_summary, missing_summary, status):
|
| 30 |
sf, connection_message = init_salesforce()
|
| 31 |
if not sf:
|
| 32 |
-
|
|
|
|
| 33 |
|
| 34 |
# Map app status to Salesforce Case.Status values
|
| 35 |
sf_status = "New" # Default for Pending and Escalated
|
|
@@ -45,10 +46,10 @@ def create_salesforce_record(score, checklist_summary, missing_summary, status):
|
|
| 45 |
"Origin": "Web", # Required field in many Salesforce orgs
|
| 46 |
"Priority": "Medium" # Required field in many Salesforce orgs
|
| 47 |
}
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
|
| 53 |
# Clean input to prevent injection attacks
|
| 54 |
def sanitize_input(text):
|
|
@@ -56,8 +57,9 @@ def sanitize_input(text):
|
|
| 56 |
return ""
|
| 57 |
return bleach.clean(text.strip())
|
| 58 |
|
| 59 |
-
# Rule-based completeness engine to evaluate readiness
|
| 60 |
-
def
|
|
|
|
| 61 |
score = 0 # Base score set to 0 for clearer range
|
| 62 |
missing_items = []
|
| 63 |
checklist_details = []
|
|
@@ -106,6 +108,9 @@ def evaluate_readiness(logs, qa_report, punch_list_text):
|
|
| 106 |
color = "red" if score < 70 else "yellow" if score < 90 else "green"
|
| 107 |
progress_bar = f'<progress value="{score}" max="100" style="width:100%;height:20px;background-color:{color}">{score}%</progress>'
|
| 108 |
|
|
|
|
|
|
|
|
|
|
| 109 |
return score, checklist_summary, missing_summary, status, progress_bar
|
| 110 |
|
| 111 |
# Generate PDF report with signature slots
|
|
@@ -134,7 +139,8 @@ with gr.Blocks(css="""progress { background-color: #f0f0f0; } .red { background-
|
|
| 134 |
gr.Markdown(
|
| 135 |
"""
|
| 136 |
# Project Closure Readiness Evaluator
|
| 137 |
-
Evaluate project readiness
|
|
|
|
| 138 |
"""
|
| 139 |
)
|
| 140 |
with gr.Row():
|
|
@@ -145,29 +151,25 @@ with gr.Blocks(css="""progress { background-color: #f0f0f0; } .red { background-
|
|
| 145 |
submit_btn = gr.Button("Evaluate Readiness")
|
| 146 |
with gr.Column(scale=3):
|
| 147 |
score_output = gr.Number(label="Readiness Score (%)")
|
| 148 |
-
progress_output = gr.HTML(
|
|
|
|
|
|
|
|
|
|
| 149 |
status_output = gr.Textbox(label="Overall Status")
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
pdf_btn = gr.Button("Download PDF Report")
|
| 155 |
pdf_output = gr.File(label="PDF Report")
|
| 156 |
|
| 157 |
-
# Connect inputs to
|
| 158 |
submit_btn.click(
|
| 159 |
-
fn=
|
| 160 |
inputs=[logs_input, qa_input, punch_input],
|
| 161 |
outputs=[score_output, checklist_output, missing_output, status_output, progress_output]
|
| 162 |
)
|
| 163 |
|
| 164 |
-
# Connect Salesforce create button to create_salesforce_record
|
| 165 |
-
sf_create_btn.click(
|
| 166 |
-
fn=create_salesforce_record,
|
| 167 |
-
inputs=[score_output, checklist_output, missing_output, status_output],
|
| 168 |
-
outputs=sf_output
|
| 169 |
-
)
|
| 170 |
-
|
| 171 |
# Connect PDF button to generate_pdf
|
| 172 |
pdf_btn.click(
|
| 173 |
fn=generate_pdf,
|
|
|
|
| 29 |
def create_salesforce_record(score, checklist_summary, missing_summary, status):
|
| 30 |
sf, connection_message = init_salesforce()
|
| 31 |
if not sf:
|
| 32 |
+
# Silently handle connection failure since UI feedback is removed
|
| 33 |
+
return
|
| 34 |
|
| 35 |
# Map app status to Salesforce Case.Status values
|
| 36 |
sf_status = "New" # Default for Pending and Escalated
|
|
|
|
| 46 |
"Origin": "Web", # Required field in many Salesforce orgs
|
| 47 |
"Priority": "Medium" # Required field in many Salesforce orgs
|
| 48 |
}
|
| 49 |
+
sf.Case.create(record)
|
| 50 |
+
except SalesforceError:
|
| 51 |
+
# Silently handle errors since UI feedback is removed
|
| 52 |
+
pass
|
| 53 |
|
| 54 |
# Clean input to prevent injection attacks
|
| 55 |
def sanitize_input(text):
|
|
|
|
| 57 |
return ""
|
| 58 |
return bleach.clean(text.strip())
|
| 59 |
|
| 60 |
+
# Rule-based completeness engine to evaluate readiness and create Salesforce record
|
| 61 |
+
def evaluate_readiness_and_save(logs, qa_report, punch_list_text):
|
| 62 |
+
# Evaluate readiness
|
| 63 |
score = 0 # Base score set to 0 for clearer range
|
| 64 |
missing_items = []
|
| 65 |
checklist_details = []
|
|
|
|
| 108 |
color = "red" if score < 70 else "yellow" if score < 90 else "green"
|
| 109 |
progress_bar = f'<progress value="{score}" max="100" style="width:100%;height:20px;background-color:{color}">{score}%</progress>'
|
| 110 |
|
| 111 |
+
# Automatically create Salesforce record
|
| 112 |
+
create_salesforce_record(score, checklist_summary, missing_summary, status)
|
| 113 |
+
|
| 114 |
return score, checklist_summary, missing_summary, status, progress_bar
|
| 115 |
|
| 116 |
# Generate PDF report with signature slots
|
|
|
|
| 139 |
gr.Markdown(
|
| 140 |
"""
|
| 141 |
# Project Closure Readiness Evaluator
|
| 142 |
+
Evaluate project readiness and generate a PDF report.
|
| 143 |
+
Results are automatically saved to Salesforce.
|
| 144 |
"""
|
| 145 |
)
|
| 146 |
with gr.Row():
|
|
|
|
| 151 |
submit_btn = gr.Button("Evaluate Readiness")
|
| 152 |
with gr.Column(scale=3):
|
| 153 |
score_output = gr.Number(label="Readiness Score (%)")
|
| 154 |
+
progress_output = gr.HTML(
|
| 155 |
+
label="Alert Indicator: Progress",
|
| 156 |
+
help_text="Color-coded readiness: Red (<70%), Yellow (70-90%), Green (>90%)"
|
| 157 |
+
)
|
| 158 |
status_output = gr.Textbox(label="Overall Status")
|
| 159 |
+
with gr.Group():
|
| 160 |
+
gr.Markdown("### Handover Summary")
|
| 161 |
+
checklist_output = gr.Textbox(label="Checklist Summary")
|
| 162 |
+
missing_output = gr.Textbox(label="Missing Items")
|
| 163 |
pdf_btn = gr.Button("Download PDF Report")
|
| 164 |
pdf_output = gr.File(label="PDF Report")
|
| 165 |
|
| 166 |
+
# Connect inputs to evaluate_readiness_and_save
|
| 167 |
submit_btn.click(
|
| 168 |
+
fn=evaluate_readiness_and_save,
|
| 169 |
inputs=[logs_input, qa_input, punch_input],
|
| 170 |
outputs=[score_output, checklist_output, missing_output, status_output, progress_output]
|
| 171 |
)
|
| 172 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
# Connect PDF button to generate_pdf
|
| 174 |
pdf_btn.click(
|
| 175 |
fn=generate_pdf,
|