weichiang commited on
Commit
23bf97f
β€’
1 Parent(s): f90b16a
Files changed (2) hide show
  1. app.py +73 -0
  2. 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