AjaykumarPilla commited on
Commit
8f3d527
Β·
verified Β·
1 Parent(s): a283630

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -3
app.py CHANGED
@@ -12,6 +12,11 @@ from reportlab.lib.units import inch
12
  from io import BytesIO
13
  from simple_salesforce import Salesforce
14
  import base64
 
 
 
 
 
15
 
16
  # Streamlit app configuration
17
  st.set_page_config(page_title="Delay πŸš€", layout="wide")
@@ -200,6 +205,7 @@ with st.form("project_form"):
200
 
201
  # Process form submission
202
  if submit_button:
 
203
  input_data = {
204
  "project_name": project_name,
205
  "phase": phase,
@@ -218,9 +224,15 @@ if submit_button:
218
  error = validate_inputs(input_data)
219
  if error:
220
  st.error(error)
 
221
  else:
222
  with st.spinner("Generating predictions and AI insights..."):
223
- prediction = predict_delay(input_data)
 
 
 
 
 
224
 
225
  if "error" in prediction:
226
  st.error(prediction["error"])
@@ -233,10 +245,21 @@ if submit_button:
233
  st.write(f"**AI Insights**: {prediction['ai_insights']}")
234
  st.write(f"**Weather Condition**: {prediction['weather_condition']}")
235
 
236
- fig = generate_heatmap(prediction['delay_probability'], f"{phase}: {task}")
237
- st.pyplot(fig)
 
 
 
 
 
 
 
 
 
 
238
 
239
  pdf_buffer = generate_pdf(input_data, prediction, fig)
 
240
  st.download_button(
241
  label="Download Prediction Report (PDF)",
242
  data=pdf_buffer,
@@ -248,8 +271,10 @@ if submit_button:
248
  sf_error = save_to_salesforce(input_data, prediction, pdf_buffer)
249
  if sf_error:
250
  st.error(sf_error)
 
251
  else:
252
  st.success("Prediction data and PDF successfully saved to Salesforce!")
 
253
 
254
  st.session_state.prediction = prediction
255
  st.session_state.input_data = input_data
 
12
  from io import BytesIO
13
  from simple_salesforce import Salesforce
14
  import base64
15
+ import logging
16
+
17
+ # Configure logging
18
+ logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
19
+ logger = logging.getLogger(__name__)
20
 
21
  # Streamlit app configuration
22
  st.set_page_config(page_title="Delay πŸš€", layout="wide")
 
205
 
206
  # Process form submission
207
  if submit_button:
208
+ logger.info("Processing form submission")
209
  input_data = {
210
  "project_name": project_name,
211
  "phase": phase,
 
224
  error = validate_inputs(input_data)
225
  if error:
226
  st.error(error)
227
+ logger.error(f"Validation error: {error}")
228
  else:
229
  with st.spinner("Generating predictions and AI insights..."):
230
+ try:
231
+ prediction = predict_delay(input_data)
232
+ except Exception as e:
233
+ st.error(f"Prediction failed: {str(e)}")
234
+ logger.error(f"Prediction failed: {str(e)}")
235
+ prediction = {"error": str(e)}
236
 
237
  if "error" in prediction:
238
  st.error(prediction["error"])
 
245
  st.write(f"**AI Insights**: {prediction['ai_insights']}")
246
  st.write(f"**Weather Condition**: {prediction['weather_condition']}")
247
 
248
+ # Generate Chart.js heatmap
249
+ chart_config = generate_heatmap(prediction['delay_probability'], f"{phase}: {task}")
250
+ st.write("```chartjs\n" + str(chart_config) + "\n```")
251
+
252
+ # Generate matplotlib figure for PDF
253
+ fig, ax = plt.subplots(figsize=(8, 2))
254
+ color = 'red' if prediction['delay_probability'] > 75 else 'yellow' if prediction['delay_probability'] > 50 else 'green'
255
+ ax.barh([f"{phase}: {task}"], [prediction['delay_probability']], color=color, edgecolor='black')
256
+ ax.set_xlim(0, 100)
257
+ ax.set_xlabel("Delay Probability (%)")
258
+ ax.set_title("Delay Risk Heatmap")
259
+ plt.tight_layout()
260
 
261
  pdf_buffer = generate_pdf(input_data, prediction, fig)
262
+ plt.close(fig)
263
  st.download_button(
264
  label="Download Prediction Report (PDF)",
265
  data=pdf_buffer,
 
271
  sf_error = save_to_salesforce(input_data, prediction, pdf_buffer)
272
  if sf_error:
273
  st.error(sf_error)
274
+ logger.error(f"Salesforce error: {sf_error}")
275
  else:
276
  st.success("Prediction data and PDF successfully saved to Salesforce!")
277
+ logger.info("Data and PDF saved to Salesforce")
278
 
279
  st.session_state.prediction = prediction
280
  st.session_state.input_data = input_data