File size: 1,828 Bytes
8a9ed0e
 
5f0ad1a
 
8a9ed0e
 
 
 
 
 
 
 
 
 
 
 
 
5f0ad1a
 
8a9ed0e
5f0ad1a
 
 
 
 
 
 
 
 
 
 
 
8a9ed0e
 
 
 
 
 
 
 
5f0ad1a
8a9ed0e
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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()