Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -314,6 +314,40 @@ def generate_pdf_content(summary, preview_df, anomalies, amc_reminders, insights
|
|
| 314 |
logging.error(f"Failed to generate PDF: {str(e)}")
|
| 315 |
return None
|
| 316 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 317 |
# Main processing function
|
| 318 |
async def process_logs(file_obj, lab_site_filter, equipment_type_filter, date_range, last_modified_state, cached_df_state, cached_filtered_df_state, current_file_path):
|
| 319 |
start_time = time.time()
|
|
@@ -437,20 +471,6 @@ async def generate_pdf(summary, preview_html, usage_chart, device_cards, daily_l
|
|
| 437 |
logging.error(f"Failed to generate PDF: {str(e)}")
|
| 438 |
return None
|
| 439 |
|
| 440 |
-
# Update filters
|
| 441 |
-
def update_filters(current_file_path, cached_df_state):
|
| 442 |
-
if not current_file_path or not cached_df_state:
|
| 443 |
-
logging.warning("No file or cached DataFrame available for filter update")
|
| 444 |
-
return gr.update(choices=['All'], value='All'), gr.update(choices=['All'], value='All')
|
| 445 |
-
try:
|
| 446 |
-
df = cached_df_state
|
| 447 |
-
lab_site_options = ['All'] + [site for site in df['lab_site'].dropna().astype(str).unique().tolist() if site.strip()] if 'lab_site' in df.columns else ['All']
|
| 448 |
-
equipment_type_options = ['All'] + [equip for equip in df['equipment_type'].dropna().astype(str).unique().tolist() if equip.strip()] if 'equipment_type' in df.columns else ['All']
|
| 449 |
-
return gr.update(choices=lab_site_options, value='All'), gr.update(choices=equipment_type_options, value='All')
|
| 450 |
-
except Exception as e:
|
| 451 |
-
logging.error(f"Failed to update filters: {str(e)}")
|
| 452 |
-
return gr.update(choices=['All'], value='All'), gr.update(choices=['All'], value='All')
|
| 453 |
-
|
| 454 |
# Gradio Interface
|
| 455 |
try:
|
| 456 |
logging.info("Initializing Gradio interface...")
|
|
@@ -528,15 +548,16 @@ try:
|
|
| 528 |
inputs=[file_input, cached_df_state, current_file_path],
|
| 529 |
outputs=[current_file_path, cached_df_state, current_file_path],
|
| 530 |
queue=False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 531 |
).then(
|
| 532 |
fn=update_filters,
|
| 533 |
inputs=[current_file_path, cached_df_state],
|
| 534 |
outputs=[lab_site_filter, equipment_type_filter],
|
| 535 |
queue=False
|
| 536 |
-
).then(
|
| 537 |
-
fn=process_logs,
|
| 538 |
-
inputs=[file_input, lab_site_filter, equipment_type_filter, date_range_filter, last_modified_state, cached_df_state, cached_filtered_df_state, current_file_path],
|
| 539 |
-
outputs=[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, pdf_output, last_modified_state, cached_df_state, cached_filtered_df_state, current_file_path]
|
| 540 |
)
|
| 541 |
|
| 542 |
# Process logs on submit or filter change
|
|
|
|
| 314 |
logging.error(f"Failed to generate PDF: {str(e)}")
|
| 315 |
return None
|
| 316 |
|
| 317 |
+
# Update filters
|
| 318 |
+
def update_filters(current_file_path, cached_df_state):
|
| 319 |
+
try:
|
| 320 |
+
if not current_file_path or cached_df_state is None:
|
| 321 |
+
logging.warning("No file or cached DataFrame available for filter update")
|
| 322 |
+
return gr.update(choices=['All'], value='All'), gr.update(choices=['All'], value='All')
|
| 323 |
+
|
| 324 |
+
df = cached_df_state
|
| 325 |
+
if df.empty:
|
| 326 |
+
logging.warning("Cached DataFrame is empty")
|
| 327 |
+
return gr.update(choices=['All'], value='All'), gr.update(choices=['All'], value='All')
|
| 328 |
+
|
| 329 |
+
lab_site_options = ['All']
|
| 330 |
+
if 'lab_site' in df.columns:
|
| 331 |
+
sites = df['lab_site'].dropna().astype(str).unique().tolist()
|
| 332 |
+
lab_site_options.extend([site for site in sites if site.strip()])
|
| 333 |
+
logging.info(f"Lab site options populated: {lab_site_options}")
|
| 334 |
+
|
| 335 |
+
equipment_type_options = ['All']
|
| 336 |
+
if 'equipment_type' in df.columns:
|
| 337 |
+
types = df['equipment_type'].dropna().astype(str).unique().tolist()
|
| 338 |
+
equipment_type_options.extend([t for t in types if t.strip()])
|
| 339 |
+
logging.info(f"Equipment type options populated: {equipment_type_options}")
|
| 340 |
+
|
| 341 |
+
if len(lab_site_options) == 1:
|
| 342 |
+
logging.warning("No valid lab_site values found in DataFrame")
|
| 343 |
+
if len(equipment_type_options) == 1:
|
| 344 |
+
logging.warning("No valid equipment_type values found in DataFrame")
|
| 345 |
+
|
| 346 |
+
return gr.update(choices=lab_site_options, value='All'), gr.update(choices=equipment_type_options, value='All')
|
| 347 |
+
except Exception as e:
|
| 348 |
+
logging.error(f"Failed to update filters: {str(e)}")
|
| 349 |
+
return gr.update(choices=['All'], value='All'), gr.update(choices=['All'], value='All')
|
| 350 |
+
|
| 351 |
# Main processing function
|
| 352 |
async def process_logs(file_obj, lab_site_filter, equipment_type_filter, date_range, last_modified_state, cached_df_state, cached_filtered_df_state, current_file_path):
|
| 353 |
start_time = time.time()
|
|
|
|
| 471 |
logging.error(f"Failed to generate PDF: {str(e)}")
|
| 472 |
return None
|
| 473 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 474 |
# Gradio Interface
|
| 475 |
try:
|
| 476 |
logging.info("Initializing Gradio interface...")
|
|
|
|
| 548 |
inputs=[file_input, cached_df_state, current_file_path],
|
| 549 |
outputs=[current_file_path, cached_df_state, current_file_path],
|
| 550 |
queue=False
|
| 551 |
+
).then(
|
| 552 |
+
fn=process_logs,
|
| 553 |
+
inputs=[file_input, lab_site_filter, equipment_type_filter, date_range_filter, last_modified_state, cached_df_state, cached_filtered_df_state, current_file_path],
|
| 554 |
+
outputs=[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, pdf_output, last_modified_state, cached_df_state, cached_filtered_df_state, current_file_path],
|
| 555 |
+
queue=False
|
| 556 |
).then(
|
| 557 |
fn=update_filters,
|
| 558 |
inputs=[current_file_path, cached_df_state],
|
| 559 |
outputs=[lab_site_filter, equipment_type_filter],
|
| 560 |
queue=False
|
|
|
|
|
|
|
|
|
|
|
|
|
| 561 |
)
|
| 562 |
|
| 563 |
# Process logs on submit or filter change
|