AjaykumarPilla commited on
Commit
d83d2ca
·
verified ·
1 Parent(s): 5b665a7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -10
app.py CHANGED
@@ -111,7 +111,6 @@ def generate_pdf_report(phase, weather, absentee_pct, delay_log, prediction, ris
111
 
112
  # Register DejaVuSans font to support Unicode emojis
113
  try:
114
- # Assuming DejaVuSans.ttf is available in the project directory
115
  pdfmetrics.registerFont(TTFont('DejaVuSans', 'DejaVuSans.ttf'))
116
  c.setFont("DejaVuSans", 12)
117
  flag_indicator = " 🚩" if prediction >= 75 else ""
@@ -299,26 +298,29 @@ try:
299
  with gr.Row():
300
  absentee_input = gr.Number(label="Absentee %", value=0)
301
  delay_input = gr.Number(label="Previous Delay Log", value=0)
302
- output = gr.Textbox(label="Prediction Summary")
 
 
303
  submit = gr.Button("Predict")
304
 
305
  def predict_and_format(phase, weather, absentee, delay_log):
306
  print("Gradio predict button clicked.")
307
  prediction, risk, insight, pdf_base64, pdf_path, heatmap_path = predict_delay(phase, weather, absentee, delay_log)
308
  if prediction is None:
309
- return f"Error: {insight}"
310
  flag = " 🚩" if prediction >= 75 else ""
311
- return (f"Predicted Delay: {prediction}%{flag}\n"
312
- f"Risk Level: {risk}\n"
313
- f"Insight: {insight}\n"
314
- f"PDF Report: {'Saved locally at ' + pdf_path if pdf_path else 'Failed to generate'}\n"
315
- f"Heatmap: {'Saved locally at ' + heatmap_path if heatmap_path else 'Failed to generate'}\n"
316
- f"PDF Base64: {'Generated' if pdf_base64 else 'Not generated'}")
 
317
 
318
  submit.click(
319
  predict_and_format,
320
  inputs=[phase_input, weather_input, absentee_input, delay_input],
321
- outputs=output
322
  )
323
  print("Gradio UI setup complete.")
324
  except Exception as e:
 
111
 
112
  # Register DejaVuSans font to support Unicode emojis
113
  try:
 
114
  pdfmetrics.registerFont(TTFont('DejaVuSans', 'DejaVuSans.ttf'))
115
  c.setFont("DejaVuSans", 12)
116
  flag_indicator = " 🚩" if prediction >= 75 else ""
 
298
  with gr.Row():
299
  absentee_input = gr.Number(label="Absentee %", value=0)
300
  delay_input = gr.Number(label="Previous Delay Log", value=0)
301
+ with gr.Row():
302
+ output_text = gr.Textbox(label="Prediction Summary")
303
+ output_pdf = gr.File(label="Download PDF Report") # Add File component for PDF
304
  submit = gr.Button("Predict")
305
 
306
  def predict_and_format(phase, weather, absentee, delay_log):
307
  print("Gradio predict button clicked.")
308
  prediction, risk, insight, pdf_base64, pdf_path, heatmap_path = predict_delay(phase, weather, absentee, delay_log)
309
  if prediction is None:
310
+ return f"Error: {insight}", None
311
  flag = " 🚩" if prediction >= 75 else ""
312
+ summary = (f"Predicted Delay: {prediction}%{flag}\n"
313
+ f"Risk Level: {risk}\n"
314
+ f"Insight: {insight}\n"
315
+ f"Heatmap: {'Saved locally at ' + heatmap_path if heatmap_path else 'Failed to generate'}\n"
316
+ f"PDF Base64: {'Generated' if pdf_base64 else 'Not generated'}")
317
+ # Return the summary text and the PDF file path for the File component
318
+ return summary, pdf_path if pdf_path and os.path.exists(pdf_path) else None
319
 
320
  submit.click(
321
  predict_and_format,
322
  inputs=[phase_input, weather_input, absentee_input, delay_input],
323
+ outputs=[output_text, output_pdf]
324
  )
325
  print("Gradio UI setup complete.")
326
  except Exception as e: