Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,12 +2,19 @@ import gradio as gr
|
|
| 2 |
import pandas as pd
|
| 3 |
import matplotlib.pyplot as plt
|
| 4 |
import numpy as np
|
| 5 |
-
from fpdf2 import FPDF
|
| 6 |
import io
|
| 7 |
from datetime import datetime, timedelta
|
| 8 |
import sys
|
| 9 |
import traceback
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
# Check library versions for debugging
|
| 12 |
debug_msg = "Library Versions:\n"
|
| 13 |
try:
|
|
@@ -16,7 +23,10 @@ try:
|
|
| 16 |
debug_msg += f"Pandas: {pd.__version__}\n"
|
| 17 |
debug_msg += f"Matplotlib: {matplotlib.__version__}\n"
|
| 18 |
debug_msg += f"NumPy: {np.__version__}\n"
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
| 20 |
except Exception as e:
|
| 21 |
debug_msg += f"Error checking library versions: {str(e)}\n"
|
| 22 |
|
|
@@ -276,6 +286,10 @@ def filter_and_visualize(selected_lab, selected_type, selected_date_range):
|
|
| 276 |
def download_pdf(selected_lab, selected_type, selected_date_range):
|
| 277 |
global df
|
| 278 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 279 |
if df.empty:
|
| 280 |
return None
|
| 281 |
|
|
@@ -335,7 +349,9 @@ try:
|
|
| 335 |
anomaly_output = gr.Textbox(label="Anomaly Alerts")
|
| 336 |
|
| 337 |
with gr.Row():
|
| 338 |
-
download_btn = gr.Button("Download PDF Report")
|
|
|
|
|
|
|
| 339 |
|
| 340 |
error_box = gr.Textbox(label="Status/Error Message", visible=True, interactive=False)
|
| 341 |
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
import matplotlib.pyplot as plt
|
| 4 |
import numpy as np
|
|
|
|
| 5 |
import io
|
| 6 |
from datetime import datetime, timedelta
|
| 7 |
import sys
|
| 8 |
import traceback
|
| 9 |
|
| 10 |
+
# Try to import fpdf2, but allow the app to run without it
|
| 11 |
+
try:
|
| 12 |
+
from fpdf2 import FPDF
|
| 13 |
+
FPDF_AVAILABLE = True
|
| 14 |
+
except ImportError:
|
| 15 |
+
FPDF_AVAILABLE = False
|
| 16 |
+
FPDF = None
|
| 17 |
+
|
| 18 |
# Check library versions for debugging
|
| 19 |
debug_msg = "Library Versions:\n"
|
| 20 |
try:
|
|
|
|
| 23 |
debug_msg += f"Pandas: {pd.__version__}\n"
|
| 24 |
debug_msg += f"Matplotlib: {matplotlib.__version__}\n"
|
| 25 |
debug_msg += f"NumPy: {np.__version__}\n"
|
| 26 |
+
if FPDF_AVAILABLE:
|
| 27 |
+
debug_msg += f"FPDF2: {FPDF.__version__}\n"
|
| 28 |
+
else:
|
| 29 |
+
debug_msg += "FPDF2: Not installed (PDF download feature disabled)\n"
|
| 30 |
except Exception as e:
|
| 31 |
debug_msg += f"Error checking library versions: {str(e)}\n"
|
| 32 |
|
|
|
|
| 286 |
def download_pdf(selected_lab, selected_type, selected_date_range):
|
| 287 |
global df
|
| 288 |
try:
|
| 289 |
+
if not FPDF_AVAILABLE:
|
| 290 |
+
print("PDF download feature disabled: fpdf2 module not installed.")
|
| 291 |
+
return None
|
| 292 |
+
|
| 293 |
if df.empty:
|
| 294 |
return None
|
| 295 |
|
|
|
|
| 349 |
anomaly_output = gr.Textbox(label="Anomaly Alerts")
|
| 350 |
|
| 351 |
with gr.Row():
|
| 352 |
+
download_btn = gr.Button("Download PDF Report", visible=FPDF_AVAILABLE)
|
| 353 |
+
if not FPDF_AVAILABLE:
|
| 354 |
+
gr.Markdown("⚠️ PDF download feature disabled: Please install fpdf2 to enable.")
|
| 355 |
|
| 356 |
error_box = gr.Textbox(label="Status/Error Message", visible=True, interactive=False)
|
| 357 |
|