Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -519,7 +519,7 @@ def generate_pdf_content(summary, preview_df, anomalies, amc_reminders, insights
|
|
| 519 |
logging.info(f"PDF generated at {pdf_path}")
|
| 520 |
return pdf_path
|
| 521 |
except Exception as e:
|
| 522 |
-
logging.error(f"Failed to generate PDF: {str(e)}")
|
| 523 |
return None
|
| 524 |
|
| 525 |
# Main processing function
|
|
@@ -633,12 +633,15 @@ async def process_logs(file_obj, lab_site_filter, equipment_type_filter, date_ra
|
|
| 633 |
# Generate PDF separately
|
| 634 |
async def generate_pdf(summary, preview_html, usage_chart, device_cards, daily_log_chart, weekly_uptime_chart, anomaly_alerts_chart, downtime_chart, anomalies, amc_reminders, insights):
|
| 635 |
try:
|
| 636 |
-
preview_df = pd.read_html(preview_html)[0]
|
| 637 |
pdf_file = generate_pdf_content(summary, preview_df, anomalies, amc_reminders, insights, device_cards, daily_log_chart, weekly_uptime_chart, anomaly_alerts_chart, downtime_chart)
|
|
|
|
|
|
|
|
|
|
| 638 |
return pdf_file
|
| 639 |
except Exception as e:
|
| 640 |
logging.error(f"Failed to generate PDF: {str(e)}")
|
| 641 |
-
return
|
| 642 |
|
| 643 |
# Update filters
|
| 644 |
def update_filters(file_obj, current_file_state):
|
|
@@ -736,7 +739,10 @@ try:
|
|
| 736 |
insights_output = gr.Markdown()
|
| 737 |
with gr.Group(elem_classes="dashboard-section"):
|
| 738 |
gr.Markdown("### Export Report")
|
| 739 |
-
pdf_output = gr.
|
|
|
|
|
|
|
|
|
|
| 740 |
|
| 741 |
file_input.change(
|
| 742 |
fn=update_filters,
|
|
@@ -754,7 +760,7 @@ try:
|
|
| 754 |
pdf_button.click(
|
| 755 |
fn=generate_pdf,
|
| 756 |
inputs=[summary_output, preview_output, usage_chart_output, device_cards_output, daily_log_trends_output, weekly_uptime_output, anomaly_alerts_output, downtime_chart_output, anomaly_output, amc_output, insights_output],
|
| 757 |
-
outputs=[pdf_output]
|
| 758 |
)
|
| 759 |
|
| 760 |
logging.info("Gradio interface initialized successfully")
|
|
|
|
| 519 |
logging.info(f"PDF generated at {pdf_path}")
|
| 520 |
return pdf_path
|
| 521 |
except Exception as e:
|
| 522 |
+
logging.error(f"Failed to generate PDF: {str(e)}. Check input data or reportlab configuration.")
|
| 523 |
return None
|
| 524 |
|
| 525 |
# Main processing function
|
|
|
|
| 633 |
# Generate PDF separately
|
| 634 |
async def generate_pdf(summary, preview_html, usage_chart, device_cards, daily_log_chart, weekly_uptime_chart, anomaly_alerts_chart, downtime_chart, anomalies, amc_reminders, insights):
|
| 635 |
try:
|
| 636 |
+
preview_df = pd.read_html(preview_html)[0] if preview_html else pd.DataFrame()
|
| 637 |
pdf_file = generate_pdf_content(summary, preview_df, anomalies, amc_reminders, insights, device_cards, daily_log_chart, weekly_uptime_chart, anomaly_alerts_chart, downtime_chart)
|
| 638 |
+
if pdf_file is None:
|
| 639 |
+
logging.warning("PDF generation failed or disabled.")
|
| 640 |
+
return "PDF generation failed. Check logs for details."
|
| 641 |
return pdf_file
|
| 642 |
except Exception as e:
|
| 643 |
logging.error(f"Failed to generate PDF: {str(e)}")
|
| 644 |
+
return f"Error generating PDF: {str(e)}"
|
| 645 |
|
| 646 |
# Update filters
|
| 647 |
def update_filters(file_obj, current_file_state):
|
|
|
|
| 739 |
insights_output = gr.Markdown()
|
| 740 |
with gr.Group(elem_classes="dashboard-section"):
|
| 741 |
gr.Markdown("### Export Report")
|
| 742 |
+
pdf_output = gr.Markdown()
|
| 743 |
+
if not reportlab_available:
|
| 744 |
+
gr.Markdown("**Note:** PDF export is unavailable because the 'reportlab' library is not installed.")
|
| 745 |
+
pdf_file_output = gr.File(label="Download Status Report as PDF")
|
| 746 |
|
| 747 |
file_input.change(
|
| 748 |
fn=update_filters,
|
|
|
|
| 760 |
pdf_button.click(
|
| 761 |
fn=generate_pdf,
|
| 762 |
inputs=[summary_output, preview_output, usage_chart_output, device_cards_output, daily_log_trends_output, weekly_uptime_output, anomaly_alerts_output, downtime_chart_output, anomaly_output, amc_output, insights_output],
|
| 763 |
+
outputs=[pdf_output, pdf_file_output]
|
| 764 |
)
|
| 765 |
|
| 766 |
logging.info("Gradio interface initialized successfully")
|