Spaces:
No application file
No application file
from typing import List | |
import gradio as gr | |
import pandas as pd | |
from app.backend.constant import LEADERBOARD_MAP | |
from app.backend.data_engine import DataEngine, COLUMNS_TYPES | |
class SubtabsComponent: | |
def __init__(self, data_engine: DataEngine): | |
self.data_engine = data_engine | |
def show(self, navigations: str = None, model_provides: List = None, evaluation_metrics: str = None, | |
embd_dtypes: str = None, embd_dims: List = None, similarity: str = None, max_tokens: int = None): | |
df_result = self.data_engine.jsons_to_df() | |
navigations = "Text" if navigations is None else navigations.split(" ", maxsplit=1)[0] | |
evaluation_metrics = "NDCG@10" if evaluation_metrics is None else evaluation_metrics | |
embd_dtype = "all" if embd_dtypes is None else embd_dtypes | |
embd_dims = [] if embd_dims is None else embd_dims | |
similarity = "all" if similarity is None else similarity | |
max_tokens = 0 if max_tokens is None else max_tokens | |
df_result = self.data_engine.filter_df(df_result, embd_dtype, embd_dims, similarity, max_tokens) | |
sort_col = evaluation_metrics.replace("@", '_at_').lower() | |
df_result = df_result.sort_values(by=sort_col, ascending=False) | |
items = [] | |
for group_name,leaderboards in LEADERBOARD_MAP.items(): | |
with gr.Column(visible=group_name.upper() == navigations.upper()) as column: | |
with gr.Tabs(): | |
with gr.TabItem("overall"): | |
df_leaderboard = df_result[df_result["group_name"] == group_name] | |
gr_df = gr.Dataframe( | |
df_leaderboard, | |
datatype=COLUMNS_TYPES, | |
# interactive=True, | |
type="pandas" | |
) | |
items.append(gr_df) | |
for leaderboard in leaderboards: | |
with gr.TabItem(leaderboard): | |
df = df_leaderboard[df_leaderboard["leaderboard"] == leaderboard] | |
gr_df = gr.Dataframe( | |
df, | |
datatype=COLUMNS_TYPES, | |
# interactive=True, | |
height=500, | |
type="pandas" | |
) | |
items.append(gr_df) | |
items.append(column) | |
return items | |