import streamlit as st
from cref import navigation
SWITCHER_STYLE = """"""
BENCHMARKS = [("fev-bench", "/"), ("CREF", "/cref")]
# Plain links, so a switch loads the other benchmark afresh instead of keeping fev's sidebar.
def switcher(current: str) -> str:
links = "".join(
f'{name}'
for name, href in BENCHMARKS
)
return f'{SWITCHER_STYLE}{current}
{links}
'
def run(fev: list[st.Page]) -> None:
cref = navigation.pages()
page = st.navigation(fev + cref, position="hidden")
# huggingface.co/spaces/autogluon/fev-bench?benchmark=cref: Hugging Face passes only the
# query string into the app, so this opens CREF on the first load.
if not st.session_state.get("routed"):
st.session_state["routed"] = True
if st.query_params.get("benchmark") == "cref" and page not in cref:
st.switch_page(cref[0])
if page in cref:
navigation.page_config()
with st.container(horizontal=True, vertical_alignment="center", gap="large"):
st.html(switcher("CREF"), width="content")
for link in cref:
st.page_link(link)
else:
with st.sidebar:
st.html(switcher("fev-bench"))
for link in fev:
st.page_link(link)
page.run()