Update app.py
Browse files
app.py
CHANGED
|
@@ -90,6 +90,9 @@ def sanitize_input(text):
|
|
| 90 |
# Rule-based completeness engine with weighted scoring
|
| 91 |
def evaluate_readiness(logs, qa_report, punch_list_text):
|
| 92 |
try:
|
|
|
|
|
|
|
|
|
|
| 93 |
# Initialize score and lists for tracking
|
| 94 |
score = 0
|
| 95 |
missing_items = []
|
|
@@ -107,30 +110,36 @@ def evaluate_readiness(logs, qa_report, punch_list_text):
|
|
| 107 |
|
| 108 |
# Process Project Logs (30% weight)
|
| 109 |
log_keywords = r"complete|handover done|finished|closed|successful"
|
| 110 |
-
|
|
|
|
| 111 |
score += LOGS_WEIGHT
|
| 112 |
checklist_details.append("Logs: Completed")
|
| 113 |
else:
|
| 114 |
missing_items.append("Project Logs Incomplete")
|
| 115 |
checklist_details.append("Logs: Pending")
|
|
|
|
| 116 |
|
| 117 |
# Process QA Report (40% weight)
|
| 118 |
qa_keywords = r"approved|passed|cleared"
|
| 119 |
-
|
|
|
|
| 120 |
score += QA_WEIGHT
|
| 121 |
checklist_details.append("QA Report: Approved")
|
| 122 |
else:
|
| 123 |
missing_items.append("QA Approval Missing")
|
| 124 |
checklist_details.append("QA Report: Pending")
|
|
|
|
| 125 |
|
| 126 |
# Process Punch List (30% weight)
|
| 127 |
punch_keywords = r"none|resolved|closed|no issues"
|
| 128 |
-
|
|
|
|
| 129 |
score += PUNCH_WEIGHT
|
| 130 |
checklist_details.append("Punch List: Resolved")
|
| 131 |
else:
|
| 132 |
missing_items.append("Open Punch Points Detected")
|
| 133 |
checklist_details.append("Punch List: Pending")
|
|
|
|
| 134 |
|
| 135 |
# Handle critical issues (escalation)
|
| 136 |
escalated = any("incomplete" in item.lower() or "missing" in item.lower() for item in missing_items)
|
|
@@ -140,10 +149,16 @@ def evaluate_readiness(logs, qa_report, punch_list_text):
|
|
| 140 |
checklist_summary = "\n".join(checklist_details)
|
| 141 |
missing_summary = "None" if not missing_items else ", ".join(missing_items)
|
| 142 |
|
| 143 |
-
# Generate progress bar HTML
|
| 144 |
-
color_class = "red" if score < 70 else "yellow" if score <= 90 else "green"
|
| 145 |
-
logging.info(f"Readiness Score: {score}%, Color Class: {color_class}")
|
| 146 |
-
progress_bar = f
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
|
| 148 |
# Automatically create Salesforce record
|
| 149 |
create_salesforce_record(score, checklist_summary, missing_summary, status)
|
|
@@ -246,10 +261,13 @@ def generate_pdf(score, checklist_summary, missing_summary, status):
|
|
| 246 |
raise
|
| 247 |
|
| 248 |
# Gradio interface with updated UI
|
| 249 |
-
with gr.Blocks(css="""
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
|
|
|
|
|
|
|
|
|
| 253 |
gr.Markdown(
|
| 254 |
"""
|
| 255 |
# Project Closure Readiness Evaluator
|
|
|
|
| 90 |
# Rule-based completeness engine with weighted scoring
|
| 91 |
def evaluate_readiness(logs, qa_report, punch_list_text):
|
| 92 |
try:
|
| 93 |
+
# Log inputs for debugging
|
| 94 |
+
logging.info(f"Inputs - Logs: {logs}, QA Report: {qa_report}, Punch List: {punch_list_text}")
|
| 95 |
+
|
| 96 |
# Initialize score and lists for tracking
|
| 97 |
score = 0
|
| 98 |
missing_items = []
|
|
|
|
| 110 |
|
| 111 |
# Process Project Logs (30% weight)
|
| 112 |
log_keywords = r"complete|handover done|finished|closed|successful"
|
| 113 |
+
logs_pass = logs and re.search(log_keywords, logs.lower())
|
| 114 |
+
if logs_pass:
|
| 115 |
score += LOGS_WEIGHT
|
| 116 |
checklist_details.append("Logs: Completed")
|
| 117 |
else:
|
| 118 |
missing_items.append("Project Logs Incomplete")
|
| 119 |
checklist_details.append("Logs: Pending")
|
| 120 |
+
logging.info(f"Logs Check: {'Pass' if logs_pass else 'Fail'}, Score so far: {score}%")
|
| 121 |
|
| 122 |
# Process QA Report (40% weight)
|
| 123 |
qa_keywords = r"approved|passed|cleared"
|
| 124 |
+
qa_pass = qa_report and re.search(qa_keywords, qa_report.lower())
|
| 125 |
+
if qa_pass:
|
| 126 |
score += QA_WEIGHT
|
| 127 |
checklist_details.append("QA Report: Approved")
|
| 128 |
else:
|
| 129 |
missing_items.append("QA Approval Missing")
|
| 130 |
checklist_details.append("QA Report: Pending")
|
| 131 |
+
logging.info(f"QA Check: {'Pass' if qa_pass else 'Fail'}, Score so far: {score}%")
|
| 132 |
|
| 133 |
# Process Punch List (30% weight)
|
| 134 |
punch_keywords = r"none|resolved|closed|no issues"
|
| 135 |
+
punch_pass = punch_list_text and re.search(punch_keywords, punch_list_text.lower())
|
| 136 |
+
if punch_pass:
|
| 137 |
score += PUNCH_WEIGHT
|
| 138 |
checklist_details.append("Punch List: Resolved")
|
| 139 |
else:
|
| 140 |
missing_items.append("Open Punch Points Detected")
|
| 141 |
checklist_details.append("Punch List: Pending")
|
| 142 |
+
logging.info(f"Punch List Check: {'Pass' if punch_pass else 'Fail'}, Final Score: {score}%")
|
| 143 |
|
| 144 |
# Handle critical issues (escalation)
|
| 145 |
escalated = any("incomplete" in item.lower() or "missing" in item.lower() for item in missing_items)
|
|
|
|
| 149 |
checklist_summary = "\n".join(checklist_details)
|
| 150 |
missing_summary = "None" if not missing_items else ", ".join(missing_items)
|
| 151 |
|
| 152 |
+
# Generate progress bar HTML using div elements
|
| 153 |
+
color_class = "red" if score < 70 else "yellow" if score <= 90 else "green"
|
| 154 |
+
logging.info(f"Readiness Score: {score}%, Color Class: {color_class}")
|
| 155 |
+
progress_bar = f"""
|
| 156 |
+
<div class="progress-container">
|
| 157 |
+
<div class="progress-bar {color_class}" style="width: {score}%;">
|
| 158 |
+
{score}%
|
| 159 |
+
</div>
|
| 160 |
+
</div>
|
| 161 |
+
"""
|
| 162 |
|
| 163 |
# Automatically create Salesforce record
|
| 164 |
create_salesforce_record(score, checklist_summary, missing_summary, status)
|
|
|
|
| 261 |
raise
|
| 262 |
|
| 263 |
# Gradio interface with updated UI
|
| 264 |
+
with gr.Blocks(css="""
|
| 265 |
+
.progress-container { background-color: #f0f0f0; width: 100%; height: 20px; border-radius: 5px; overflow: hidden; position: relative; }
|
| 266 |
+
.progress-bar { height: 100%; text-align: center; line-height: 20px; color: #000; font-size: 12px; }
|
| 267 |
+
.progress-bar.red { background-color: #FF0000; }
|
| 268 |
+
.progress-bar.yellow { background-color: #FFFF00; }
|
| 269 |
+
.progress-bar.green { background-color: #00FF00; }
|
| 270 |
+
""") as demo:
|
| 271 |
gr.Markdown(
|
| 272 |
"""
|
| 273 |
# Project Closure Readiness Evaluator
|