|
import json |
|
import gradio as gr |
|
from huggingface_hub import CommitScheduler |
|
from pathlib import Path |
|
import requests |
|
from huggingface_hub import HfApi, HfFolder |
|
import os |
|
|
|
|
|
token = os.getenv('stb_leaderboard_json') |
|
HfFolder.save_token(token) |
|
|
|
def load_data(): |
|
url = "https://huggingface.co./datasets/stabletoolbench/StableToolBench_data/resolve/main/leaderboard_data.json" |
|
response = requests.get(url) |
|
data = response.json() |
|
return data |
|
|
|
|
|
existing_data = load_data() |
|
|
|
|
|
dataset_dir = Path("my_dataset") |
|
dataset_dir.mkdir(parents=True, exist_ok=True) |
|
|
|
|
|
scheduler = CommitScheduler( |
|
repo_id="stabletoolbench/StableToolBench_data", |
|
repo_type="dataset", |
|
folder_path=dataset_dir, |
|
path_in_repo="", |
|
) |
|
|
|
|
|
def generate_table(data): |
|
if not data: |
|
return [], [] |
|
|
|
|
|
valid_data = [entry for entry in data if 'Scores' in entry and isinstance(entry['Scores'], dict)] |
|
|
|
|
|
sorted_data = sorted(valid_data, key=lambda x: x['Scores'].get('Average', 0), reverse=True) |
|
|
|
|
|
headers = ["Method"] + list(sorted_data[0]['Scores'].keys()) if sorted_data else ["Method"] |
|
|
|
rows = [] |
|
for entry in sorted_data: |
|
row = [entry['Method']] + [entry['Scores'].get(key, "N/A") for key in headers[1:]] |
|
rows.append(row) |
|
|
|
return headers, rows |
|
|
|
|
|
protected_methods = ["GPT-4-Turbo-Preview (DFS)", "GPT-3.5-Turbo-1106 (DFS)", "GPT-4-0613 (DFS)", "GPT-3.5-Turbo-0613 (DFS)", "GPT-4-Turbo-Preview (CoT)", "ToolLLaMA v2 (DFS)", "GPT-4-0613 (CoT)", "GPT-3.5-Turbo-1106 (CoT)", "GPT-3.5-Turbo-0613 (CoT)", "ToolLLaMA v2 (CoT)"] |
|
|
|
|
|
def merge_data(uploaded_data_json): |
|
|
|
new_data = uploaded_data_json |
|
|
|
with scheduler.lock: |
|
|
|
|
|
def merge_scores(existing_scores, new_scores): |
|
for key, value in new_scores.items(): |
|
existing_scores[key] = value |
|
|
|
|
|
for new_entry in new_data["SolvablePassRateScores"]: |
|
if new_entry["Method"] not in protected_methods: |
|
existing_entry = next( |
|
(item for item in existing_data["SolvablePassRateScores"] if item["Method"] == new_entry["Method"]), |
|
None) |
|
if existing_entry: |
|
|
|
merge_scores(existing_entry["Scores"], new_entry["Scores"]) |
|
else: |
|
|
|
existing_data["SolvablePassRateScores"].append(new_entry) |
|
|
|
|
|
for new_entry in new_data["SolvableWinRateScores"]: |
|
if new_entry["Method"] not in protected_methods: |
|
existing_entry = next( |
|
(item for item in existing_data["SolvableWinRateScores"] if item["Method"] == new_entry["Method"]), |
|
None) |
|
if existing_entry: |
|
merge_scores(existing_entry["Scores"], new_entry["Scores"]) |
|
else: |
|
existing_data["SolvableWinRateScores"].append(new_entry) |
|
|
|
data_file_path = dataset_dir / "leaderboard_data.json" |
|
with open(data_file_path, 'w') as file: |
|
json.dump(existing_data, file, indent=4) |
|
|
|
return existing_data |
|
|
|
def process_file(file_info): |
|
if file_info is not None: |
|
with open(file_info, "r") as uploaded_file: |
|
data_content = uploaded_file.read() |
|
uploaded_data_json = json.loads(data_content) |
|
|
|
merge_data(uploaded_data_json) |
|
|
|
pass_rate_table, win_rate_table = refresh_table_data() |
|
return pass_rate_table, win_rate_table |
|
|
|
def refresh_table_data(): |
|
|
|
new_data = load_data() |
|
|
|
new_pass_rate_data = generate_table(new_data["SolvablePassRateScores"])[1] |
|
new_win_rate_data = generate_table(new_data["SolvableWinRateScores"])[1] |
|
|
|
return new_pass_rate_data, new_win_rate_data |
|
|
|
with gr.Blocks() as app: |
|
|
|
|
|
gr.Markdown("# StableToolBench Leaderboard") |
|
|
|
|
|
gr.Markdown(""" |
|
**Large Language Models (LLMs)** have witnessed remarkable advancements in recent years, prompting the exploration of tool learning, which integrates LLMs with external tools to address diverse real-world challenges. Assessing the capability of LLMs to utilise tools necessitates large-scale and stable benchmarks. However, previous works relied on either hand-crafted online tools with limited scale, or large-scale real online APIs suffering from instability of API status. To address this problem, we introduce StableToolBench, a benchmark evolving from ToolBench, proposing a virtual API server and stable evaluation system. The virtual API server contains a caching system and API simulators which are complementary to alleviate the change in API status. Meanwhile, the stable evaluation system designs solvable pass and win rates using GPT-4 as the automatic evaluator to eliminate the randomness during evaluation. Experimental results demonstrate the stability of StableToolBench, and further discuss the effectiveness of API simulators, the caching system, and the evaluation system. |
|
""") |
|
gr.Markdown(""" ### For further information, please refer to: """) |
|
buttons_html = """ |
|
<style> |
|
.custom-link-button { |
|
font-size: 18px !important; /* Adjust the font size as needed */ |
|
padding: 10px 15px !important; /* Add some padding */ |
|
margin: 5px !important; |
|
color: white !important; /* Text color */ |
|
background-color: #106BA3 !important; /* Background color */ |
|
text-decoration: none !important; /* Remove underline from links */ |
|
display: inline-block !important; |
|
border-radius: 5px !important; /* Rounded corners */ |
|
border: none !important; /* Remove borders */ |
|
cursor: pointer !important; /* Mouse pointer on hover */ |
|
text-align: center !important; |
|
} |
|
.custom-link-button:hover { |
|
background-color: #0D5B8F !important; |
|
} |
|
</style> |
|
<a href="https://arxiv.org/pdf/2403.07714.pdf" target="_blank" class="custom-link-button">Paper</a> |
|
<a href="https://arxiv.org/abs/2403.07714" target="_blank" class="custom-link-button">arXiv</a> |
|
<a href="https://github.com/zhichengg/StableToolBench" target="_blank" class="custom-link-button">Code</a> |
|
<a href="https://drive.google.com/file/d/1XUiCMA5NV359UGR-eknF0TcXORuR7RXj/view?pli=1" target="_blank" class="custom-link-button">Cache Data</a> |
|
""" |
|
|
|
gr.HTML(buttons_html) |
|
|
|
gr.Markdown("## Solvable Pass Rate Scores") |
|
headers1, rows1 = generate_table(existing_data["SolvablePassRateScores"]) |
|
table1 = gr.Dataframe(headers=headers1, value=rows1, interactive=False) |
|
|
|
gr.Markdown("## Solvable Win Rate Scores") |
|
headers2, rows2 = generate_table(existing_data["SolvableWinRateScores"]) |
|
table2 = gr.Dataframe(headers=headers2, value=rows2, interactive=False) |
|
|
|
refresh_button = gr.Button("Refresh Leaderboards") |
|
refresh_button.click( |
|
fn=refresh_table_data, |
|
outputs=[table1, table2] |
|
) |
|
|
|
gr.Markdown("## Upload Your Own Results") |
|
gr.Markdown(""" |
|
If you would like to contribute to the leaderboard, please follow the JSON structure below for your method's scores. |
|
|
|
**Solvable Pass Rate Scores Template:** |
|
```json |
|
{ |
|
"SolvablePassRateScores": [ |
|
{ |
|
"Method": "Your Method Name", |
|
"Scores": { |
|
"I1 Instruction": 85.5, |
|
"I1 Instruction SE": 1.2, |
|
"I1 Category": 80.0, |
|
"I1 Category SE": 1.0, |
|
"I1 Tool": 88.5, |
|
"I1 Tool SE": 0.8, |
|
"I2 Category": 82.5, |
|
"I2 Category SE": 1.3, |
|
"I2 Instruction": 86.0, |
|
"I2 Instruction SE": 0.5, |
|
"I3 Instruction": 90.0, |
|
"I3 Instruction SE": 0.7, |
|
"Average": 87.5, |
|
"Average SE": 1.1 |
|
} |
|
} |
|
// Add more methods here... |
|
], |
|
"SolvableWinRateScores": [ |
|
{ |
|
"Method": "Your Method Name", |
|
"Scores": { |
|
"I1 Instruction": 65.0, |
|
"I1 Category": 68.5, |
|
"I1 Tool": 66.8, |
|
"I2 Category": 70.0, |
|
"I2 Instruction": 69.2, |
|
"I3 Instruction": 71.5, |
|
"Average": 68.5 |
|
} |
|
} |
|
// Add more methods here... |
|
] |
|
} |
|
``` |
|
|
|
Make sure your uploaded JSON file follows this structure. |
|
""") |
|
|
|
upload_component = gr.File(label="Upload JSON File") |
|
submit_button = gr.Button("Submit") |
|
submit_button.click( |
|
fn=process_file, |
|
inputs= upload_component, |
|
outputs=[table1, table2] |
|
) |
|
|
|
gr.Markdown(" ## If you like our project, please consider cite our work as follows: ") |
|
citation_text = """ |
|
``` |
|
@misc{guo2024stabletoolbench, |
|
title={StableToolBench: Towards Stable Large-Scale Benchmarking on Tool Learning of Large Language Models}, |
|
author={Zhicheng Guo and Sijie Cheng and Hao Wang and Shihao Liang and Yujia Qin and Peng Li and Zhiyuan Liu and Maosong Sun and Yang Liu}, |
|
year={2024}, |
|
eprint={2403.07714}, |
|
archivePrefix={arXiv}, |
|
primaryClass={cs.CL} |
|
} |
|
``` |
|
""" |
|
gr.Markdown(citation_text) |
|
|
|
if __name__ == "__main__": |
|
app.launch() |
|
scheduler.commit() |
|
|