Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -57,7 +57,7 @@ project_choices = [
|
|
| 57 |
"Project Alpha", "Project Beta", "Project Gamma", "Project Delta", "Project Epsilon",
|
| 58 |
"Project Zeta", "Project Theta", "Project Sigma", "Project Omega", "Project Phoenix"
|
| 59 |
]
|
| 60 |
-
ai_suggestion_choices = ["Move", "Repair", "Replace"]
|
| 61 |
|
| 62 |
def validate_date(last_maint):
|
| 63 |
try:
|
|
@@ -83,7 +83,6 @@ def call_ai_model(usage, idle, freq, cost, last):
|
|
| 83 |
utilization_ratio = usage / total if total > 0 else 0.0
|
| 84 |
utilization_percent = utilization_ratio * 100
|
| 85 |
|
| 86 |
-
# Determine suggestion (no "Pause Rent")
|
| 87 |
if utilization_percent < 60:
|
| 88 |
sug = "Move"
|
| 89 |
elif utilization_percent < 80:
|
|
@@ -100,7 +99,6 @@ def call_ai_model(usage, idle, freq, cost, last):
|
|
| 100 |
base_conf *= (0.7 + 0.3 * freq_factor)
|
| 101 |
confidence = max(0.05, min(base_conf, 1.0))
|
| 102 |
|
| 103 |
-
# Round before return
|
| 104 |
return sug, round(confidence, 2), round(utilization_percent, 2)
|
| 105 |
|
| 106 |
except Exception as e:
|
|
@@ -112,13 +110,10 @@ def process_equipment_utilization(equip, proj, use_h, idle_h, move_f, cost_h, la
|
|
| 112 |
if not sf:
|
| 113 |
raise ValueError("Salesforce connection is not initialized. Please check credentials and try again.")
|
| 114 |
|
| 115 |
-
# Validate the Last Maintenance date
|
| 116 |
last_maint = validate_date(last_maint)
|
| 117 |
|
| 118 |
-
# Always run AI model to get suggestion, confidence, score
|
| 119 |
ai_sug_generated, conf, score = call_ai_model(use_h, idle_h, move_f, cost_h, last_maint)
|
| 120 |
|
| 121 |
-
# Use manual suggestion if provided, else AI suggestion
|
| 122 |
suggestion_to_use = ai_sug if ai_sug else ai_sug_generated
|
| 123 |
|
| 124 |
for field, value in [("Usage Hours", use_h), ("Idle Hours", idle_h),
|
|
@@ -136,7 +131,7 @@ def process_equipment_utilization(equip, proj, use_h, idle_h, move_f, cost_h, la
|
|
| 136 |
"Usage Hours": use_h,
|
| 137 |
"Idle Hours": idle_h,
|
| 138 |
"Suggestion": suggestion_to_use,
|
| 139 |
-
"Confidence": conf * 100,
|
| 140 |
"Utilization Score": score,
|
| 141 |
"Cost per Hour": cost_h,
|
| 142 |
"Last Maintenance": last_maint or "N/A"
|
|
@@ -216,17 +211,17 @@ def format_batch_output(records):
|
|
| 216 |
|
| 217 |
# Start by creating a header for each record
|
| 218 |
record_details = [
|
| 219 |
-
f"Record {i}:",
|
| 220 |
-
f"
|
| 221 |
-
f"
|
| 222 |
-
f"
|
| 223 |
-
f"
|
| 224 |
-
f"
|
| 225 |
-
f"
|
| 226 |
-
f"
|
| 227 |
-
f"
|
| 228 |
-
f"
|
| 229 |
-
f"
|
| 230 |
]
|
| 231 |
lines.append("\n".join(record_details))
|
| 232 |
lines.append("\n---\n") # Separator between records
|
|
@@ -387,7 +382,7 @@ with gr.Blocks() as app:
|
|
| 387 |
submit_btn.click(
|
| 388 |
fn=manual_input,
|
| 389 |
inputs=[equipment_dropdown, project_dropdown, usage, idle, freq, cost, last, ai_dropdown],
|
| 390 |
-
outputs=[result_txt, report_file]
|
| 391 |
)
|
| 392 |
clear_btn.click(lambda: ("", None), None, [result_txt, report_file])
|
| 393 |
with gr.TabItem("CSV Upload"):
|
|
@@ -404,7 +399,7 @@ with gr.Blocks() as app:
|
|
| 404 |
outputs=[csv_output, batch_pdf]
|
| 405 |
)
|
| 406 |
clear_btn.click(
|
| 407 |
-
lambda: (None, "", None),
|
| 408 |
None,
|
| 409 |
[csv_file, csv_output, batch_pdf]
|
| 410 |
)
|
|
|
|
| 57 |
"Project Alpha", "Project Beta", "Project Gamma", "Project Delta", "Project Epsilon",
|
| 58 |
"Project Zeta", "Project Theta", "Project Sigma", "Project Omega", "Project Phoenix"
|
| 59 |
]
|
| 60 |
+
ai_suggestion_choices = ["Move", "Repair", "Replace"]
|
| 61 |
|
| 62 |
def validate_date(last_maint):
|
| 63 |
try:
|
|
|
|
| 83 |
utilization_ratio = usage / total if total > 0 else 0.0
|
| 84 |
utilization_percent = utilization_ratio * 100
|
| 85 |
|
|
|
|
| 86 |
if utilization_percent < 60:
|
| 87 |
sug = "Move"
|
| 88 |
elif utilization_percent < 80:
|
|
|
|
| 99 |
base_conf *= (0.7 + 0.3 * freq_factor)
|
| 100 |
confidence = max(0.05, min(base_conf, 1.0))
|
| 101 |
|
|
|
|
| 102 |
return sug, round(confidence, 2), round(utilization_percent, 2)
|
| 103 |
|
| 104 |
except Exception as e:
|
|
|
|
| 110 |
if not sf:
|
| 111 |
raise ValueError("Salesforce connection is not initialized. Please check credentials and try again.")
|
| 112 |
|
|
|
|
| 113 |
last_maint = validate_date(last_maint)
|
| 114 |
|
|
|
|
| 115 |
ai_sug_generated, conf, score = call_ai_model(use_h, idle_h, move_f, cost_h, last_maint)
|
| 116 |
|
|
|
|
| 117 |
suggestion_to_use = ai_sug if ai_sug else ai_sug_generated
|
| 118 |
|
| 119 |
for field, value in [("Usage Hours", use_h), ("Idle Hours", idle_h),
|
|
|
|
| 131 |
"Usage Hours": use_h,
|
| 132 |
"Idle Hours": idle_h,
|
| 133 |
"Suggestion": suggestion_to_use,
|
| 134 |
+
"Confidence": conf * 100,
|
| 135 |
"Utilization Score": score,
|
| 136 |
"Cost per Hour": cost_h,
|
| 137 |
"Last Maintenance": last_maint or "N/A"
|
|
|
|
| 211 |
|
| 212 |
# Start by creating a header for each record
|
| 213 |
record_details = [
|
| 214 |
+
f"Record {i}: {summary.get('Equipment Name', 'N/A')}",
|
| 215 |
+
f"Salesforce Record ID: {rec['Salesforce_Record_Id']}",
|
| 216 |
+
f"Equipment Name: {summary.get('Equipment Name', 'N/A')}",
|
| 217 |
+
f"Project: {summary.get('Project', 'N/A')}",
|
| 218 |
+
f"Usage Hours: {summary.get('Usage Hours', 0):.2f}",
|
| 219 |
+
f"Idle Hours: {summary.get('Idle Hours', 0):.2f}",
|
| 220 |
+
f"Suggestion: {summary.get('Suggestion', 'N/A')}",
|
| 221 |
+
f"Confidence: {summary.get('Confidence', 0):.2f}",
|
| 222 |
+
f"Utilization Score: {summary.get('Utilization Score', 0):.2f}",
|
| 223 |
+
f"Cost per Hour: ₹{summary.get('Cost per Hour', 0):,.2f}",
|
| 224 |
+
f"Last Maintenance: {summary.get('Last Maintenance', 'N/A')}"
|
| 225 |
]
|
| 226 |
lines.append("\n".join(record_details))
|
| 227 |
lines.append("\n---\n") # Separator between records
|
|
|
|
| 382 |
submit_btn.click(
|
| 383 |
fn=manual_input,
|
| 384 |
inputs=[equipment_dropdown, project_dropdown, usage, idle, freq, cost, last, ai_dropdown],
|
| 385 |
+
outputs=[result_txt, report_file]
|
| 386 |
)
|
| 387 |
clear_btn.click(lambda: ("", None), None, [result_txt, report_file])
|
| 388 |
with gr.TabItem("CSV Upload"):
|
|
|
|
| 399 |
outputs=[csv_output, batch_pdf]
|
| 400 |
)
|
| 401 |
clear_btn.click(
|
| 402 |
+
lambda: (None, "", None),
|
| 403 |
None,
|
| 404 |
[csv_file, csv_output, batch_pdf]
|
| 405 |
)
|