agh123's picture
add guide to submit
124754e
raw
history blame
4.15 kB
import asyncio
import streamlit as st
import pandas as pd
from typing import Optional, List, Set, Tuple
from .components.filters import render_table_filters
from .components.visualizations import (
render_leaderboard_table,
render_performance_plots,
)
from .components.header import render_header, render_contribution_guide
from .services.firebase import fetch_leaderboard_data
from .core.styles import CUSTOM_CSS
def get_filter_values(
df: pd.DataFrame,
) -> tuple[
List[str],
List[str],
List[str],
List[str],
List[str],
Tuple[int, int],
Tuple[int, int],
Tuple[int, int],
List[str],
int,
]:
"""Get unique values for filters"""
models = sorted(df["Model ID"].unique().tolist())
platforms = sorted(df["Platform"].unique().tolist())
devices = sorted(df["Device"].unique().tolist())
cache_type_v = sorted(df["cache_type_v"].unique().tolist())
cache_type_k = sorted(df["cache_type_k"].unique().tolist())
n_threads = (df["n_threads"].min(), df["n_threads"].max())
max_n_gpu_layers = max(df["n_gpu_layers"].unique().tolist())
pp_range = (df["PP Config"].min(), df["PP Config"].max())
tg_range = (df["TG Config"].min(), df["TG Config"].max())
versions = sorted(df["Version"].unique().tolist())
return (
models,
platforms,
devices,
cache_type_v,
cache_type_k,
pp_range,
tg_range,
n_threads,
versions,
max_n_gpu_layers,
)
async def main():
"""Main application entry point"""
st.set_page_config(
page_title="AI Phone Benchmark Leaderboard",
page_icon="πŸ“±",
layout="wide",
)
# Apply custom styles
st.markdown(CUSTOM_CSS, unsafe_allow_html=True)
# Fetch initial data
df = await fetch_leaderboard_data()
if df.empty:
st.error("No data available. Please check your connection and try again.")
return
# Render header
render_header()
# Get unique values for filters
(
models,
platforms,
devices,
cache_type_v,
cache_type_k,
pp_range,
tg_range,
n_threads,
versions,
max_n_gpu_layers,
) = get_filter_values(df)
# Create main layout with sidebar for contribution guide
main_col, guide_col = st.columns([0.8, 0.2])
with main_col:
# Render filters
table_filters = render_table_filters(
models,
platforms,
devices,
cache_type_v,
cache_type_k,
pp_range,
tg_range,
n_threads,
versions,
max_n_gpu_layers,
)
# Render the main leaderboard table
render_leaderboard_table(df, table_filters)
# Render plot section
st.markdown("---")
st.title("πŸ“Š Performance Comparison")
# Plot specific selectors in a row
plot_col1, plot_col2, plot_col3 = st.columns(3)
with plot_col1:
plot_model = st.selectbox(
"Select Model for Comparison", options=models, key="plot_model_selector"
)
with plot_col2:
plot_pp = st.selectbox(
"Select PP Config for Comparison",
options=sorted([int(x) for x in df["PP Config"].unique()]),
key="plot_pp_selector",
)
with plot_col3:
plot_tg = st.selectbox(
"Select TG Config for Comparison",
options=sorted([int(x) for x in df["TG Config"].unique()]),
key="plot_tg_selector",
)
# Create plot filters based on table filters but override the model and configs
plot_filters = table_filters.copy()
plot_filters["model"] = plot_model
plot_filters["pp_range"] = (plot_pp, plot_pp) # Set exact PP value
plot_filters["tg_range"] = (plot_tg, plot_tg) # Set exact TG value
render_performance_plots(df, plot_filters)
with guide_col:
render_contribution_guide()
if __name__ == "__main__":
asyncio.run(main())