Skip to content

Commit

Permalink
save added to the main page, fixed session state keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Kacper-W-Kozdon committed May 10, 2024
1 parent 2b7cc9a commit d6b3ceb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
22 changes: 22 additions & 0 deletions chatbot_arena.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,28 @@ async def call(unify_obj, model, contain, message):
st.session_state["chat_history1"] = []
st.session_state["chat_history2"] = []

with st.sidebar:
st.button("Save leaderboards", key="save")
if st.session_state.save:

helpers.database.save_offline()
try:
helpers.database.save_online()
except Exception as e:
st.write("Could not upload the results.")
st.write(e)
st.session_state.leaderboard[["Wins ⭐", "Losses ❌"]] = (
st.session_state.leaderboard[["Wins ⭐", "Losses ❌"]].where(
st.session_state.leaderboard[["Wins ⭐", "Losses ❌"]] == 0, 0
)
)

st.session_state.detailed_leaderboards["scores"] = (
st.session_state.detailed_leaderboards["scores"].where(
st.session_state.detailed_leaderboards["scores"] == 0, 0
)
)


if __name__ == "__main__":
asyncio.run(main())
4 changes: 2 additions & 2 deletions helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def get_offline(update: bool = False) -> None:

if not update:
st.session_state.leaderboard = pd.DataFrame(json_data)
st.session_state.detailed_leaderboard = st.session_state.offline_detailed
st.session_state.detailed_leaderboards = st.session_state.offline_detailed
st.session_state.models = st.session_state.offline_models

st.session_state.leaderboard[["Wins ⭐", "Losses ❌"]] = (
Expand Down Expand Up @@ -176,7 +176,7 @@ def get_online(update: bool = False):

if not update:
st.session_state.leaderboard = gsheets_leaderboard
st.session_state.detailed_leaderboard = {"scores": gsheets_detail}
st.session_state.detailed_leaderboards = {"scores": gsheets_detail}
st.session_state.models = gsheets_models["Models"]

st.session_state.leaderboard[["Wins ⭐", "Losses ❌"]] = (
Expand Down
12 changes: 6 additions & 6 deletions pages/1_leaderboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
sorted_counts.sort_values(by=["Wins ⭐", "Losses ❌"], inplace=True)
sorted_counts.index = range(sorted_counts.shape[0])

detail_leaderboards = st.session_state.detailed_leaderboard["scores"].add(
detail_leaderboards = st.session_state.detailed_leaderboards["scores"].add(
st.session_state.offline_detailed["scores"], fill_value=0
)

Expand All @@ -39,7 +39,7 @@

if source == "online":
helpers.database.get_online(True)
detail_leaderboards = st.session_state.detailed_leaderboard["scores"].add(
detail_leaderboards = st.session_state.detailed_leaderboards["scores"].add(
st.session_state.online_detailed["scores"], fill_value=0
)

Expand Down Expand Up @@ -74,7 +74,7 @@
["Compare", "Model Name", "Wins ⭐", "Losses ❌"]
]

detail_leaderboards = st.session_state.detailed_leaderboard
detail_leaderboards = st.session_state.detailed_leaderboards
model_selection = list(detail_leaderboards["scores"].keys())[1:]

if st.session_state.enable_detail:
Expand Down Expand Up @@ -156,8 +156,8 @@
)
)

st.session_state.detailed_leaderboard["scores"] = (
st.session_state.detailed_leaderboard["scores"].where(
st.session_state.detailed_leaderboard["scores"] == 0, 0
st.session_state.detailed_leaderboards["scores"] = (
st.session_state.detailed_leaderboards["scores"].where(
st.session_state.detailed_leaderboards["scores"] == 0, 0
)
)

0 comments on commit d6b3ceb

Please sign in to comment.