44"""
55
66import argparse
7- import pickle
8- import time
9- from typing import List
10-
117import gradio as gr
128
139from fastchat .serve .gradio_block_arena_anony import (
5450logger = build_logger ("gradio_web_server_multi" , "gradio_web_server_multi.log" )
5551
5652
53+ def build_visualizer ():
54+ visualizer_markdown = """
55+ # 🔍 Arena Visualizer
56+ This tool provides an interactive way to explore how people are using Chatbot Arena.
57+ Using *[topic clustering](https://github.com/MaartenGr/BERTopic)*, we organized user-submitted prompts from Arena battles into broad and specific categories.
58+ Dive in to uncover insights about the distribution and themes of these prompts!
59+ """
60+ gr .Markdown (visualizer_markdown , elem_id = "visualizer_markdown" )
61+ expandText = "👇 Expand to see detailed instructions on how to use the visualizer"
62+ with gr .Accordion (expandText , open = False ):
63+ instructions = """
64+ - Hover Over Segments: View the category name, the number of prompts, and their percentage.
65+ - *On mobile devices*: Tap instead of hover.
66+ - Click to Explore:
67+ - Click on a main category to see its subcategories.
68+ - Click on subcategories to see example prompts in the sidebar.
69+ - Undo and Reset: Click the center of the chart to return to the top level.
70+
71+ Visualizer is created using Arena battle data collected from 2024/6 to 2024/8.
72+ """
73+ gr .Markdown (instructions )
74+
75+ frame = """
76+ <iframe class="visualizer" width="100%"
77+ src="https://storage.googleapis.com/public-arena-no-cors/index.html">
78+ </iframe>
79+ """
80+ gr .HTML (frame )
81+
82+
5783def load_demo (context : Context , request : gr .Request ):
5884 ip = get_ip (request )
5985 logger .info (f"load_demo. ip: { ip } . params: { request .query_params } " )
@@ -199,12 +225,14 @@ def build_demo(
199225 arena_hard_table ,
200226 show_plot = True ,
201227 )
228+ if args .show_visualizer :
229+ with gr .Tab ("🔍 Arena Visualizer" , id = 5 ):
230+ build_visualizer ()
202231
203232 with gr .Tab ("ℹ️ About Us" , id = 4 ):
204- about = build_about ()
233+ build_about ()
205234
206235 context_state = gr .State (context )
207- url_params = gr .JSON (visible = False )
208236
209237 if args .model_list_mode not in ["once" , "reload" ]:
210238 raise ValueError (f"Unknown model list mode: { args .model_list_mode } " )
@@ -271,7 +299,8 @@ def build_demo(
271299 parser .add_argument (
272300 "--gradio-auth-path" ,
273301 type = str ,
274- help = 'Set the gradio authentication file path. The file should contain one or more user:password pairs in this format: "u1:p1,u2:p2,u3:p3"' ,
302+ help = 'Set the gradio authentication file path. The file should contain one or \
303+ more user:password pairs in this format: "u1:p1,u2:p2,u3:p3"' ,
275304 default = None ,
276305 )
277306 parser .add_argument (
@@ -286,7 +315,8 @@ def build_demo(
286315 parser .add_argument (
287316 "--gradio-root-path" ,
288317 type = str ,
289- help = "Sets the gradio root path, eg /abc/def. Useful when running behind a reverse-proxy or at a custom URL path prefix" ,
318+ help = "Sets the gradio root path, eg /abc/def. Useful when running behind a \
319+ reverse-proxy or at a custom URL path prefix" ,
290320 )
291321 parser .add_argument (
292322 "--ga-id" ,
@@ -305,6 +335,12 @@ def build_demo(
305335 type = str ,
306336 help = "Set the password for the gradio web server" ,
307337 )
338+ parser .add_argument (
339+ "--show-visualizer" ,
340+ action = "store_true" ,
341+ default = False ,
342+ help = "Show the Data Visualizer tab" ,
343+ )
308344 args = parser .parse_args ()
309345 logger .info (f"args: { args } " )
310346
0 commit comments