adding_leaderboard_back (#33)
Browse files- adding leaderboard back! (dd2eba6ad95fa53f8b5fbd6dc15574ec138bb2eb)
- small change (80bb49b20cd80470dda61efdaa5844784556a0f5)
- mirror fschat repo (576afc533bc7923c200150b7ed662d55dea9c054)
- added mirror arg (62bf7e6ab36b1fae9c745a42bb2eeb50a03b7dd6)
- you're welcome (2e49e3e0ceac8ca576896955e6a9bbc8dce29b65)
- app.py +73 -0
- requirements.txt +2 -1
app.py
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastchat.serve.monitor.monitor import build_leaderboard_tab, build_basic_stats_tab, basic_component_values, leader_component_values
|
2 |
+
from fastchat.utils import build_logger, get_window_url_params_js
|
3 |
+
|
4 |
+
import argparse
|
5 |
+
import glob
|
6 |
+
import re
|
7 |
+
import gradio as gr
|
8 |
+
|
9 |
+
def load_demo(url_params, request: gr.Request):
|
10 |
+
logger.info(f"load_demo. ip: {request.client.host}. params: {url_params}")
|
11 |
+
return basic_component_values + leader_component_values
|
12 |
+
|
13 |
+
def build_demo(elo_results_file, leaderboard_table_file):
|
14 |
+
from fastchat.serve.gradio_web_server import block_css
|
15 |
+
|
16 |
+
text_size = gr.themes.sizes.text_lg
|
17 |
+
|
18 |
+
with gr.Blocks(
|
19 |
+
title="Monitor",
|
20 |
+
theme=gr.themes.Base(text_size=text_size),
|
21 |
+
css=block_css,
|
22 |
+
) as demo:
|
23 |
+
with gr.Tabs() as tabs:
|
24 |
+
with gr.Tab("Leaderboard", id=0):
|
25 |
+
leader_components = build_leaderboard_tab(
|
26 |
+
elo_results_file,
|
27 |
+
leaderboard_table_file,
|
28 |
+
show_plot=True,
|
29 |
+
mirror=True
|
30 |
+
)
|
31 |
+
|
32 |
+
with gr.Tab("Basic Stats", id=1):
|
33 |
+
basic_components = build_basic_stats_tab()
|
34 |
+
|
35 |
+
url_params = gr.JSON(visible=False)
|
36 |
+
demo.load(
|
37 |
+
load_demo,
|
38 |
+
[url_params],
|
39 |
+
basic_components + leader_components,
|
40 |
+
)
|
41 |
+
|
42 |
+
return demo
|
43 |
+
|
44 |
+
if __name__ == "__main__":
|
45 |
+
parser = argparse.ArgumentParser()
|
46 |
+
parser.add_argument("--share", action="store_true")
|
47 |
+
parser.add_argument("--host", default="0.0.0.0")
|
48 |
+
parser.add_argument("--port", type=int, default=7860)
|
49 |
+
args = parser.parse_args()
|
50 |
+
|
51 |
+
logger = build_logger("monitor", "monitor.log")
|
52 |
+
logger.info(f"args: {args}")
|
53 |
+
|
54 |
+
elo_result_files = glob.glob("elo_results_*.pkl")
|
55 |
+
def extract_sort_key(filename):
|
56 |
+
match = re.search(r'(\d{8})-(\d+)', filename)
|
57 |
+
if match:
|
58 |
+
# Extract the date and identifier parts, converting them to integers for sorting
|
59 |
+
date_part = int(match.group(1))
|
60 |
+
id_part = int(match.group(2))
|
61 |
+
return (date_part, id_part)
|
62 |
+
else:
|
63 |
+
# Fallback sort key if the filename does not match the expected format
|
64 |
+
return (0, 0)
|
65 |
+
elo_result_files.sort(key=lambda x: extract_sort_key(x[12:-4]))
|
66 |
+
elo_result_file = elo_result_files[-1]
|
67 |
+
|
68 |
+
leaderboard_table_files = glob.glob("leaderboard_table_*.csv")
|
69 |
+
leaderboard_table_files.sort(key=lambda x: extract_sort_key(x[18:-4]))
|
70 |
+
leaderboard_table_file = leaderboard_table_files[-1]
|
71 |
+
|
72 |
+
demo = build_demo(elo_result_file, leaderboard_table_file)
|
73 |
+
demo.launch(share=args.share, server_name=args.host, server_port=args.port)
|
requirements.txt
CHANGED
@@ -1 +1,2 @@
|
|
1 |
-
plotly
|
|
|
|
1 |
+
plotly
|
2 |
+
git+https://github.com/lm-sys/FastChat.git@main
|