Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -4,6 +4,7 @@ import pandas as pd
|
|
4 |
from apscheduler.schedulers.background import BackgroundScheduler
|
5 |
from huggingface_hub import snapshot_download
|
6 |
import numpy as np
|
|
|
7 |
|
8 |
from src.about import (
|
9 |
CITATION_BUTTON_LABEL,
|
@@ -29,39 +30,82 @@ from src.envs import API, EVAL_REQUESTS_PATH, EVAL_RESULTS_PATH, QUEUE_REPO, REP
|
|
29 |
from src.populate import get_evaluation_queue_df, get_leaderboard_df
|
30 |
from src.submission.submit import add_new_eval
|
31 |
|
|
|
|
|
|
|
|
|
32 |
|
33 |
def restart_space():
|
34 |
API.restart_space(repo_id=REPO_ID)
|
35 |
|
36 |
### Space initialisation
|
37 |
-
try:
|
38 |
-
print(EVAL_REQUESTS_PATH)
|
39 |
-
snapshot_download(
|
40 |
-
repo_id=QUEUE_REPO, local_dir=EVAL_REQUESTS_PATH, repo_type="dataset", tqdm_class=None, etag_timeout=30, token=TOKEN
|
41 |
-
)
|
42 |
-
except Exception as e:
|
43 |
-
print(f"Erro ao baixar EVAL_REQUESTS: {e}")
|
44 |
-
try:
|
45 |
-
print(EVAL_RESULTS_PATH)
|
46 |
-
snapshot_download(
|
47 |
-
repo_id=RESULTS_REPO, local_dir=EVAL_RESULTS_PATH, repo_type="dataset", tqdm_class=None, etag_timeout=30, token=TOKEN
|
48 |
-
)
|
49 |
-
except Exception as e:
|
50 |
-
print(f"Erro ao baixar EVAL_RESULTS: {e}")
|
51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
ALL_COLS = [c.name for c in fields(AutoEvalColumn)]
|
53 |
|
|
|
54 |
try:
|
55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
except Exception as e:
|
57 |
print(f"Erro ao gerar o DataFrame do Leaderboard: {e}")
|
58 |
-
LEADERBOARD_DF = pd.DataFrame()
|
59 |
|
60 |
-
(
|
|
|
|
|
61 |
finished_eval_queue_df,
|
62 |
running_eval_queue_df,
|
63 |
pending_eval_queue_df,
|
64 |
-
) = get_evaluation_queue_df(EVAL_REQUESTS_PATH, EVAL_COLS)
|
65 |
|
66 |
|
67 |
def create_leaderboard_component(dataframe, displayed_cols, hidden_cols=None, cant_deselect_cols=None, title=None):
|
|
|
4 |
from apscheduler.schedulers.background import BackgroundScheduler
|
5 |
from huggingface_hub import snapshot_download
|
6 |
import numpy as np
|
7 |
+
import os
|
8 |
|
9 |
from src.about import (
|
10 |
CITATION_BUTTON_LABEL,
|
|
|
30 |
from src.populate import get_evaluation_queue_df, get_leaderboard_df
|
31 |
from src.submission.submit import add_new_eval
|
32 |
|
33 |
+
# --- TESTE: Carregar dados locais ---
|
34 |
+
TEST_DATA_PATH = "output/leaderboard_data_20250413_002339.csv" # Ajuste o caminho se necessário
|
35 |
+
LOAD_TEST_DATA = True # Defina como False para usar dados do Hub
|
36 |
+
# -------
|
37 |
|
38 |
def restart_space():
|
39 |
API.restart_space(repo_id=REPO_ID)
|
40 |
|
41 |
### Space initialisation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
+
if not LOAD_TEST_DATA:
|
44 |
+
try:
|
45 |
+
print(EVAL_REQUESTS_PATH)
|
46 |
+
snapshot_download(
|
47 |
+
repo_id=QUEUE_REPO, local_dir=EVAL_REQUESTS_PATH, repo_type="dataset", tqdm_class=None, etag_timeout=30, token=TOKEN
|
48 |
+
)
|
49 |
+
except Exception as e: # Adicionar captura de exceção
|
50 |
+
print(f"Erro ao baixar EVAL_REQUESTS: {e}")
|
51 |
+
# Considerar restart_space() aqui também, dependendo da severidade
|
52 |
+
try:
|
53 |
+
print(EVAL_RESULTS_PATH)
|
54 |
+
snapshot_download(
|
55 |
+
repo_id=RESULTS_REPO, local_dir=EVAL_RESULTS_PATH, repo_type="dataset", tqdm_class=None, etag_timeout=30, token=TOKEN
|
56 |
+
)
|
57 |
+
except Exception as e: # Adicionar captura de exceção
|
58 |
+
print(f"Erro ao baixar EVAL_RESULTS: {e}")
|
59 |
+
# Considerar restart_space() aqui também
|
60 |
+
else:
|
61 |
+
print(f"Modo de teste: Carregando dados locais de {TEST_DATA_PATH}")
|
62 |
+
EVAL_RESULTS_PATH = None # Não precisamos do caminho do Hub para resultados
|
63 |
+
EVAL_REQUESTS_PATH = "data/eval_requests" # Manter ou ajustar se a fila ainda for lida do Hub
|
64 |
+
# Certifique-se de que o diretório da fila de requests existe se for usado
|
65 |
+
os.makedirs(EVAL_REQUESTS_PATH, exist_ok=True)
|
66 |
+
|
67 |
+
|
68 |
+
# Obter todas as colunas definidas
|
69 |
ALL_COLS = [c.name for c in fields(AutoEvalColumn)]
|
70 |
|
71 |
+
# Obter o leaderboard completo com as médias calculadas
|
72 |
try:
|
73 |
+
initial_df_for_test = None
|
74 |
+
if LOAD_TEST_DATA:
|
75 |
+
try:
|
76 |
+
initial_df_for_test = pd.read_csv(TEST_DATA_PATH)
|
77 |
+
# Renomear colunas do CSV para corresponder às chaves internas (task.name)
|
78 |
+
# Esta parte pode precisar de ajustes dependendo dos nomes exatos das colunas no CSV
|
79 |
+
rename_map = {task.value.col_name: task.name for task in Tasks}
|
80 |
+
# Adicionar mapeamento para outras colunas se necessário (ex: 'Model' -> 'model')
|
81 |
+
rename_map["Model"] = AutoEvalColumn.model.name # Exemplo
|
82 |
+
# Adicione outros mapeamentos conforme necessário
|
83 |
+
initial_df_for_test.rename(columns=rename_map, inplace=True)
|
84 |
+
print("DataFrame de teste carregado e colunas renomeadas.")
|
85 |
+
except FileNotFoundError:
|
86 |
+
print(f"Erro: Arquivo de teste não encontrado em {TEST_DATA_PATH}")
|
87 |
+
initial_df_for_test = pd.DataFrame()
|
88 |
+
except Exception as e:
|
89 |
+
print(f"Erro ao carregar ou processar o arquivo de teste: {e}")
|
90 |
+
initial_df_for_test = pd.DataFrame()
|
91 |
+
|
92 |
+
LEADERBOARD_DF = get_leaderboard_df(
|
93 |
+
results_path=EVAL_RESULTS_PATH if not LOAD_TEST_DATA else None,
|
94 |
+
requests_path=EVAL_REQUESTS_PATH if not LOAD_TEST_DATA else None,
|
95 |
+
cols=ALL_COLS,
|
96 |
+
initial_df=initial_df_for_test
|
97 |
+
)
|
98 |
except Exception as e:
|
99 |
print(f"Erro ao gerar o DataFrame do Leaderboard: {e}")
|
100 |
+
LEADERBOARD_DF = pd.DataFrame() # Criar DataFrame vazio em caso de erro
|
101 |
|
102 |
+
# Obter DataFrames da fila de avaliação (pode precisar ser ajustado se LOAD_TEST_DATA=True)
|
103 |
+
# Se a fila também deve ser mockada/lida localmente, ajuste aqui
|
104 |
+
(
|
105 |
finished_eval_queue_df,
|
106 |
running_eval_queue_df,
|
107 |
pending_eval_queue_df,
|
108 |
+
) = get_evaluation_queue_df(EVAL_REQUESTS_PATH, EVAL_COLS)
|
109 |
|
110 |
|
111 |
def create_leaderboard_component(dataframe, displayed_cols, hidden_cols=None, cant_deselect_cols=None, title=None):
|