File size: 12,222 Bytes
2dba94f dbd7a03 2dba94f 49268fc 2dba94f dbd7a03 2dba94f dbd7a03 4dcba74 2dba94f 49268fc 2dba94f 49268fc 86aa3b5 49268fc 2dba94f 1f3e8c7 2dba94f 49268fc 2dba94f 49268fc 2dba94f dbd7a03 2dba94f dbd7a03 49268fc dbd7a03 2dba94f dbd7a03 e3a5d5a dbd7a03 2dba94f dbd7a03 e045c4a 2dba94f dbd7a03 2dba94f 49268fc 2dba94f 49268fc 2dba94f dbd7a03 2dba94f dbd7a03 49268fc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
import os
import gradio as gr
import pandas as pd
import json
import plotly.graph_objects as go
from plotly.subplots import make_subplots
from collections import Counter
from apscheduler.schedulers.background import BackgroundScheduler
import numpy as np
from scorer import question_scorer
from content import format_error, format_warning, format_log, TITLE, LINKS, INTRODUCTION_TEXT, LEADERBOARD_TEXT, CITATION_BUTTON_LABEL, EVALUATION_DETAILS, CITATION_BUTTON_TEXT, model_hyperlink, SUBMIT_INTRODUCTION
TOKEN = os.environ.get("TOKEN", None)
OWNER = "Online-Mind2Web"
YEAR_VERSION = "2025"
LOCAL_DEBUG = True
def _format_sr_column(series: pd.Series) -> pd.Series:
numeric = pd.to_numeric(series, errors="coerce")
out = numeric.map(lambda x: f"{x:.1f}" if pd.notna(x) else "")
# Wherever coercion failed (original was str / NaN), restore original value
mask = numeric.isna() & series.notna()
out[mask] = series[mask]
return out
def get_dataframe_from_results(eval_path):
df = pd.read_csv(eval_path)
if "Verified" not in df.columns:
df = df.sort_values(by=["Average SR"], ascending=False)
else:
df = df.sort_values(
by=["Verified", "Average SR"],
ascending=[False, False],
kind="mergesort"
)
for col in ['Easy', 'Medium', 'Hard', 'Average SR']:
if col in df.columns:
df[col] = _format_sr_column(df[col])
return df
auto_eval_dataframe_test = get_dataframe_from_results('./auto_o4-mini_Mind2Web-Online - Leaderboard_data.csv')
human_eval_dataframe_test = get_dataframe_from_results('./human_Mind2Web-Online - Leaderboard_data.csv')
TYPES = ["str", "str", "str", "markdown", "number", "number", "number", "number", "str", "str", "markdown", "str"]
def df_to_gradio(df: pd.DataFrame) -> dict:
display_df = df.drop(columns=["Release Time"], errors="ignore")
headers = display_df.columns.tolist()
data = display_df.values.tolist()
# simple styling: red if not verified
if "Verified" in display_df.columns:
verified_idx = headers.index("Verified")
styling = [["background-color:#ffcccc" if not row[verified_idx] else "" for _ in headers] for row in data]
else:
styling = [["" for _ in headers] for _ in data]
return {"data": data, "headers": headers, "metadata": {"styling": styling}}
def gradio_plot_wrapper(json_file):
return plot_heatmap_with_performance_bar(json_file.name)
def style_auto_df(df: pd.DataFrame):
def _row_style(row):
bg = "background-color: #ffcccc" if row["Verified"] != True else ""
return [bg] * len(row)
styler = df.style.apply(_row_style, axis=1)
try:
styler = styler.hide(axis="index")
except Exception:
pass
return styler
def nice_bounds(low: float, high: float) -> tuple[float, float]:
if low == high:
low -= 1; high += 1
return (np.floor(low / 5) * 5, np.ceil(high / 5) * 5)
def plot_sr_vs_time(df: pd.DataFrame, title: str = "Success rate over time") -> go.Figure:
work = df[df["Verified"] == True].copy() # filter out unverified rows
work["Release Time"] = pd.to_datetime(work["Release Time"], errors="coerce")
work["Average SR"] = pd.to_numeric(work["Average SR"], errors="coerce")
work = work.dropna(subset=["Release Time", "Average SR"])
agents = work["Agent"].unique().tolist()
color_map = {a: f"hsl({int(360*i/len(agents))},70%,45%)" for i, a in enumerate(agents)}
fig = go.Figure()
y_min_raw, y_max_raw = work["Average SR"].min(), work["Average SR"].max()
y_min, y_max = nice_bounds(y_min_raw, y_max_raw)
band_edges = np.linspace(y_min, y_max, 4)
band_cols = ["rgba(226,247,226,0.35)", "rgba(255,255,204,0.35)", "rgba(255,228,225,0.35)"]
shapes = [
dict(type="rect", xref="paper", yref="y", x0=0, x1=1, y0=band_edges[i], y1=band_edges[i+1],
fillcolor=band_cols[i], line_width=0)
for i in range(3)
]
for _, row in work.iterrows():
fig.add_trace(
go.Scatter(
x=[row["Release Time"]],
y=[row["Average SR"]],
mode="markers+text",
text=[row["Agent"]],
textposition="top center",
textfont=dict(size=11),
marker=dict(size=10, color=color_map[row["Agent"]], opacity=0.9),
hovertemplate="Agent: %{text}<br>SR: %{y:.1f}%<br>Date: %{x|%Y-%m}<extra></extra>",
showlegend=False,
)
)
if len(work) >= 2:
x_numeric = work["Release Time"].map(pd.Timestamp.toordinal)
slope, intercept = np.polyfit(x_numeric, work["Average SR"], 1)
x_range = pd.date_range(work["Release Time"].min(), work["Release Time"].max(), freq="MS")
y_pred = slope * x_range.map(pd.Timestamp.toordinal) + intercept
fig.add_trace(go.Scatter(x=x_range, y=y_pred, mode="lines", line=dict(color="rgba(0,0,0,0.6)", dash="dash"), name="Trend", hoverinfo="skip"))
fig.update_layout(
title=dict(text=title, x=0.5, xanchor="center", font=dict(size=22)),
xaxis_title="Release Time",
yaxis_title="Success Rate",
template="plotly_white",
width=1800, height=800,
shapes=shapes,
)
fig.update_xaxes(dtick="M1", tickformat="%Y-%m", showspikes=True, spikemode="across", spikecolor="rgba(0,0,0,0.4)", spikethickness=1, spikedash="dot")
fig.update_yaxes(showspikes=True, spikemode="across", spikecolor="rgba(0,0,0,0.4)", spikethickness=1, spikedash="dot")
return fig
def plot_heatmap_with_performance_bar(json_file):
with open(json_file, "r") as f:
data = json.load(f)
agents = [k for k in data[0].keys() if k.endswith("_human_label")]
records = []
original_ids = [task["task_id"] for task in data]
for task in data:
task_id = task["task_id"]
for agent in agents:
raw_val = task.get(agent, "0")
try:
val = int(raw_val)
except ValueError:
val = 0
val = 1 if val == 1 else 0
records.append({
"Task ID": task_id,
"Agent": agent.replace("_human_label", ""),
"Success": val
})
df = pd.DataFrame(records)
pivot = df.pivot_table(index="Agent", columns="Task ID", values="Success", aggfunc="max")
for task_id in original_ids:
if task_id not in pivot.columns:
pivot[task_id] = 0
pivot = pivot[original_ids]
agent_success_rate = pivot.sum(axis=1) / pivot.shape[1]
pivot["SuccessRate"] = agent_success_rate
pivot = pivot.sort_values(by="SuccessRate", ascending=False)
pivot = pivot.drop(columns=["SuccessRate"])
agent_name_map = {
"Operator": "Operator",
"Agent-E": "Agent-E",
"Browser_Use": "Browser Use",
"Claude_Computer_Use": "Claude Computer Use",
"SeeAct": "SeeAct"
}
sorted_agents = pivot.index.tolist()
pivot.index = [
f"{agent_name_map.get(agent, agent)} ({agent_success_rate[agent]*100:.1f}%)"
for agent in sorted_agents
]
custom_labels = [["Success" if val == 1 else "Failure" for val in row] for row in pivot.values]
any_agent_solved = pivot.max(axis=0).sum()
best_agent_solved = pivot.sum(axis=1).max()
total_tasks = len(original_ids)
fig = make_subplots(
rows=2, cols=1,
row_heights=[0.8, 0.2],
vertical_spacing=0.08,
subplot_titles=("TASK ID", ""),
shared_xaxes=False
)
fig.add_trace(go.Heatmap(
z=pivot.values,
x=pivot.columns,
y=pivot.index,
colorscale=[[0, "white"], [1, "skyblue"]],
zmin=0,
zmax=1,
showscale=False,
customdata=custom_labels,
hovertemplate="Agent: %{y}<br>Task ID: %{x}<br>Completion: %{customdata}<extra></extra>"
), row=1, col=1)
fig.add_trace(go.Bar(
y=["Any agent", "Best agent"],
x=[any_agent_solved, best_agent_solved],
orientation='h',
marker_color=["dodgerblue", "mediumseagreen"],
text=[
f"{int(any_agent_solved)}/{total_tasks} ({any_agent_solved / total_tasks:.1%})",
f"{int(best_agent_solved)}/{total_tasks} ({best_agent_solved / total_tasks:.1%})"
],
textposition="auto",
showlegend=False
), row=2, col=1)
fig.add_trace(go.Scatter(
x=[None], y=[None],
mode='markers',
marker=dict(size=10, color='skyblue'),
name='Success'
))
fig.add_trace(go.Scatter(
x=[None], y=[None],
mode='markers',
marker=dict(size=10, color='white', line=dict(width=1, color='black')),
name='Failure'
))
fig.update_xaxes(range=[0, total_tasks], row=2, col=1)
fig.update_layout(
height=600,
xaxis=dict(showticklabels=False),
yaxis=dict(title="Agent"),
yaxis2=dict(title=""),
margin=dict(t=60)
)
return fig
def refresh():
auto_eval_dataframe_test = get_dataframe_from_results('./auto_o4-mini_Mind2Web-Online - Leaderboard_data.csv')
human_eval_dataframe_test = get_dataframe_from_results('./human_Mind2Web-Online - Leaderboard_data.csv')
sr_time_plot = plot_sr_vs_time(auto_eval_dataframe_test)
auto_eval_dataframe_test = gr.Dataframe(value=df_to_gradio(auto_eval_dataframe_test), datatype=TYPES, interactive=False, wrap=False, elem_id="auto-leaderboard-table")
return auto_eval_dataframe_test, human_eval_dataframe_test, sr_time_plot
demo = gr.Blocks(css="""#human-leaderboard-table { width: auto; min-width: calc(100% + 20px); }""")
with demo:
gr.HTML(TITLE)
gr.HTML(LINKS)
gr.Markdown(INTRODUCTION_TEXT, elem_classes="markdown-text")
with gr.Row():
with gr.Accordion("π Citation", open=False):
citation_button = gr.Textbox(
value=CITATION_BUTTON_TEXT,
label=CITATION_BUTTON_LABEL,
elem_id="citation-button",
lines=10,
)
gr.Markdown(LEADERBOARD_TEXT, elem_classes="markdown-text")
with gr.Tab("Human Evaluation", elem_id="human-tab", id=1):
human_leaderboard_table_test = gr.Dataframe(
value=human_eval_dataframe_test,
datatype=TYPES,
interactive=False,
wrap=False
)
gr.Markdown("### Visualization")
gr.Markdown("This figure presents a fine-grained heatmap illustrating task-level completion across different agents. Each row corresponds to a specific agent, and each column represents a task (identified by its task ID). Blue bars indicate successful completions, while white spaces denote failures. Any agent: A task is considered successful if at least one agent is able to complete it. (This style of visualization is inspired by [HAL](https://hal.cs.princeton.edu/).)")
fig = plot_heatmap_with_performance_bar("./human_label.json")
gr.Plot(fig)
gr.Markdown(EVALUATION_DETAILS)
with gr.Tab("Auto Evaluation", elem_id="auto-tab", id=2):
sr_time_plot = gr.Plot(plot_sr_vs_time(auto_eval_dataframe_test))
gr.Markdown('### Agents highlighted in red represent unverified results that may involve unreliable evaluations and are provided for reference only. You can refer to the "Note" column for more details.')
auto_leaderboard_table_test = gr.Dataframe(value=df_to_gradio(auto_eval_dataframe_test), datatype=TYPES, interactive=False, wrap=False, elem_id="auto-leaderboard-table")
with gr.Tab("Submission Guideline", elem_id="submit-tab", id=3):
with gr.Row():
gr.Markdown(SUBMIT_INTRODUCTION, elem_classes="markdown-text")
refresh_button = gr.Button("Refresh")
refresh_button.click(
refresh,
inputs=[],
outputs=[
auto_leaderboard_table_test,
human_leaderboard_table_test,
sr_time_plot
],
)
scheduler = BackgroundScheduler()
scheduler.start()
if __name__ == "__main__":
demo.launch(debug=True,share=True)
|