import pandas as pd import streamlit as st import time import os @st.cache_data(hash_funcs={pd.DataFrame: lambda _: None}) def load_leaderboard(file_path="data/results_df_all_tuned.csv"): """ Tải và xử lý file CSV chứa kết quả leaderboard của các mô hình. Args: file_path (str): Đường dẫn đến file CSV leaderboard. Returns: pd.DataFrame: DataFrame đã được sắp xếp, sẵn sàng để hiển thị. """ try: # Time the read to help diagnose cold-starts on hosted platforms start = time.time() df = pd.read_csv(file_path) elapsed = time.time() - start # Report file size and load time to the Streamlit console/UI for diagnostics try: fsize_mb = os.path.getsize(file_path) / (1024 * 1024) except Exception: fsize_mb = 0.0 # If load took longer than a short threshold, surface an informational note if elapsed > 0.5: st.info(f"Loaded leaderboard file '{file_path}' ({fsize_mb:.2f} MB) in {elapsed:.2f} s") SORT_COLUMN_NAME = 'RMSE (Absolute Error)' if SORT_COLUMN_NAME in df.columns: df_sorted = df.sort_values(by=SORT_COLUMN_NAME, ascending=True) else: st.warning(f"Không tìm thấy cột '{SORT_COLUMN_NAME}' để sắp xếp leaderboard. " f"Vui lòng kiểm tra file `src/benchmark_utils.py`.") df_sorted = df return df_sorted except FileNotFoundError: st.error(f"LỖI: Không tìm thấy file leaderboard tại đường dẫn: {file_path}") return pd.DataFrame() # Trả về DataFrame rỗng nếu có lỗi except Exception as e: st.error(f"Lỗi khi tải leaderboard: {e}") return pd.DataFrame()