Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -111,6 +111,7 @@ def generate_pdf_report(phase, weather, absentee_pct, delay_log, prediction, ris
|
|
| 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,29 +299,26 @@ try:
|
|
| 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 |
-
|
| 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}"
|
| 311 |
flag = " π©" if prediction >= 75 else ""
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 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=
|
| 324 |
)
|
| 325 |
print("Gradio UI setup complete.")
|
| 326 |
except Exception as e:
|
|
|
|
| 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 |
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:
|