Update app.py
Browse files
app.py
CHANGED
|
@@ -198,7 +198,6 @@ def generate_pdf(input_data, prediction, heatmap_fig, gantt_fig):
|
|
| 198 |
f"Task Actual Duration: {input_data['task_actual_duration']} days",
|
| 199 |
f"Workforce Gap: {input_data['workforce_gap']}%",
|
| 200 |
f"Workforce Skill Level: {input_data['workforce_skill_level']}",
|
| 201 |
-
f"Workforce Shift Hours: {input_data['workforce_shift_hours']}",
|
| 202 |
f"Weather Impact Score: {input_data['weather_impact_score']}",
|
| 203 |
f"Weather Condition: {input_data['weather_condition']}",
|
| 204 |
f"Weather Forecast Date: {input_data['weather_forecast_date']}",
|
|
@@ -254,7 +253,7 @@ def generate_pdf(input_data, prediction, heatmap_fig, gantt_fig):
|
|
| 254 |
buffer.seek(0)
|
| 255 |
return buffer
|
| 256 |
|
| 257 |
-
# Function to save data to Salesforce, including PDF
|
| 258 |
def save_to_salesforce(input_data, prediction, pdf_buffer):
|
| 259 |
if sf is None:
|
| 260 |
return "Salesforce connection not established."
|
|
@@ -334,42 +333,67 @@ def save_to_salesforce(input_data, prediction, pdf_buffer):
|
|
| 334 |
logger.error(f"Error saving to Salesforce: {str(e)}")
|
| 335 |
return f"Error saving to Salesforce: {str(e)}"
|
| 336 |
|
| 337 |
-
#
|
| 338 |
-
col1, col2 = st.columns(2)
|
| 339 |
-
with col1:
|
| 340 |
-
phase = st.selectbox("Phase", [""] + ["Planning", "Design", "Construction"], index=0, key="phase_select")
|
| 341 |
-
|
| 342 |
-
# Update task options and reset task when phase changes
|
| 343 |
-
if phase != st.session_state.get("phase", ""):
|
| 344 |
-
st.session_state.phase = phase
|
| 345 |
-
st.session_state.task = ""
|
| 346 |
-
if "task_select" in st.session_state:
|
| 347 |
-
del st.session_state.task_select
|
| 348 |
-
logger.info(f"Phase changed to {phase}, resetting task and task_select")
|
| 349 |
-
|
| 350 |
-
# Define task options based on phase
|
| 351 |
-
task_options_list = [""] + task_options.get(phase, []) if phase else [""]
|
| 352 |
-
logger.info(f"Task options for phase '{phase}': {task_options_list}")
|
| 353 |
-
task = st.selectbox("Task", task_options_list, index=0, key="task_select")
|
| 354 |
-
|
| 355 |
-
# Input form for other fields
|
| 356 |
with st.form("project_form"):
|
| 357 |
-
|
|
|
|
|
|
|
| 358 |
|
| 359 |
with col1:
|
| 360 |
-
project_name = st.text_input("Project Name")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 361 |
current_progress = st.number_input("Current Progress (%)", min_value=0.0, max_value=100.0, step=1.0, value=0.0)
|
| 362 |
task_expected_duration = st.number_input("Task Expected Duration (days)", min_value=0, step=1, value=0)
|
| 363 |
task_actual_duration = st.number_input("Task Actual Duration (days)", min_value=0, step=1, value=0)
|
| 364 |
|
| 365 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 366 |
workforce_gap = st.number_input("Workforce Gap (%)", min_value=0.0, max_value=100.0, step=1.0, value=0.0)
|
| 367 |
workforce_skill_level = st.selectbox("Workforce Skill Level", ["", "Low", "Medium", "High"], index=0)
|
|
|
|
|
|
|
| 368 |
workforce_shift_hours = st.number_input("Workforce Shift Hours", min_value=0, step=1, value=0)
|
| 369 |
st.write(f"**Selected Shift Hours**: {workforce_shift_hours}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 370 |
project_location = st.text_input("Project Location (City)", placeholder="e.g., New York")
|
|
|
|
|
|
|
| 371 |
weather_forecast_date = st.date_input("Weather Forecast Date", min_value=datetime(2025, 1, 1), value=None)
|
| 372 |
|
|
|
|
|
|
|
| 373 |
submit_button = st.form_submit_button("Fetch Weather and Predict Delay")
|
| 374 |
|
| 375 |
# Process form submission
|
|
|
|
| 198 |
f"Task Actual Duration: {input_data['task_actual_duration']} days",
|
| 199 |
f"Workforce Gap: {input_data['workforce_gap']}%",
|
| 200 |
f"Workforce Skill Level: {input_data['workforce_skill_level']}",
|
|
|
|
| 201 |
f"Weather Impact Score: {input_data['weather_impact_score']}",
|
| 202 |
f"Weather Condition: {input_data['weather_condition']}",
|
| 203 |
f"Weather Forecast Date: {input_data['weather_forecast_date']}",
|
|
|
|
| 253 |
buffer.seek(0)
|
| 254 |
return buffer
|
| 255 |
|
| 256 |
+
# Function to save data to Salesforce, including PDF
|
| 257 |
def save_to_salesforce(input_data, prediction, pdf_buffer):
|
| 258 |
if sf is None:
|
| 259 |
return "Salesforce connection not established."
|
|
|
|
| 333 |
logger.error(f"Error saving to Salesforce: {str(e)}")
|
| 334 |
return f"Error saving to Salesforce: {str(e)}"
|
| 335 |
|
| 336 |
+
# Input form with improved UI and dynamic Task field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 337 |
with st.form("project_form"):
|
| 338 |
+
# Project Details Section
|
| 339 |
+
st.markdown("### Project Details")
|
| 340 |
+
col1, col2 = st.columns([1, 1])
|
| 341 |
|
| 342 |
with col1:
|
| 343 |
+
project_name = st.text_input("Project Name", placeholder="Enter project name")
|
| 344 |
+
phase = st.selectbox("Phase", [""] + ["Planning", "Design", "Construction"], index=0, key="phase_select")
|
| 345 |
+
|
| 346 |
+
# Update session state when phase changes
|
| 347 |
+
if phase != st.session_state.get("phase", ""):
|
| 348 |
+
st.session_state.phase = phase
|
| 349 |
+
st.session_state.task = ""
|
| 350 |
+
if "task_select" in st.session_state:
|
| 351 |
+
del st.session_state.task_select
|
| 352 |
+
logger.info(f"Phase changed to {phase}, resetting task and task_select")
|
| 353 |
+
|
| 354 |
+
# Define task options based on phase
|
| 355 |
+
task_options_list = [""] + task_options.get(phase, []) if phase else [""]
|
| 356 |
+
logger.info(f"Task options for phase '{phase}': {task_options_list}")
|
| 357 |
+
|
| 358 |
+
# Use a placeholder to dynamically update the Task selectbox
|
| 359 |
+
task_placeholder = st.empty()
|
| 360 |
+
task = task_placeholder.selectbox("Task", task_options_list, index=0, key="task_select")
|
| 361 |
+
|
| 362 |
+
with col2:
|
| 363 |
current_progress = st.number_input("Current Progress (%)", min_value=0.0, max_value=100.0, step=1.0, value=0.0)
|
| 364 |
task_expected_duration = st.number_input("Task Expected Duration (days)", min_value=0, step=1, value=0)
|
| 365 |
task_actual_duration = st.number_input("Task Actual Duration (days)", min_value=0, step=1, value=0)
|
| 366 |
|
| 367 |
+
# Divider
|
| 368 |
+
st.markdown("---")
|
| 369 |
+
|
| 370 |
+
# Workforce Details Section
|
| 371 |
+
st.markdown("### Workforce Details")
|
| 372 |
+
col3, col4 = st.columns([1, 1])
|
| 373 |
+
|
| 374 |
+
with col3:
|
| 375 |
workforce_gap = st.number_input("Workforce Gap (%)", min_value=0.0, max_value=100.0, step=1.0, value=0.0)
|
| 376 |
workforce_skill_level = st.selectbox("Workforce Skill Level", ["", "Low", "Medium", "High"], index=0)
|
| 377 |
+
|
| 378 |
+
with col4:
|
| 379 |
workforce_shift_hours = st.number_input("Workforce Shift Hours", min_value=0, step=1, value=0)
|
| 380 |
st.write(f"**Selected Shift Hours**: {workforce_shift_hours}")
|
| 381 |
+
|
| 382 |
+
# Divider
|
| 383 |
+
st.markdown("---")
|
| 384 |
+
|
| 385 |
+
# Location and Weather Section
|
| 386 |
+
st.markdown("### Location and Weather")
|
| 387 |
+
col5, col6 = st.columns([1, 1])
|
| 388 |
+
|
| 389 |
+
with col5:
|
| 390 |
project_location = st.text_input("Project Location (City)", placeholder="e.g., New York")
|
| 391 |
+
|
| 392 |
+
with col6:
|
| 393 |
weather_forecast_date = st.date_input("Weather Forecast Date", min_value=datetime(2025, 1, 1), value=None)
|
| 394 |
|
| 395 |
+
# Submit Button
|
| 396 |
+
st.write("") # Add some spacing
|
| 397 |
submit_button = st.form_submit_button("Fetch Weather and Predict Delay")
|
| 398 |
|
| 399 |
# Process form submission
|