JarvisKi commited on
Commit
7d88617
1 Parent(s): d39beb1

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -252
app.py DELETED
@@ -1,252 +0,0 @@
1
- import json
2
- import gradio as gr
3
- from huggingface_hub import CommitScheduler
4
- from pathlib import Path
5
- import requests
6
- from huggingface_hub import HfApi, HfFolder
7
- import os
8
- # Use the token from an environment variable
9
- token = os.getenv('stb_leaderboard_json')
10
- HfFolder.save_token(token)
11
-
12
- def load_data():
13
- url = "https://huggingface.co/datasets/stabletoolbench/StableToolBench_data/resolve/main/leaderboard_data.json"
14
- response = requests.get(url)
15
- data = response.json() # 将下载的内容解析为 JSON
16
- return data
17
-
18
- existing_data = load_data()
19
-
20
- # 创建本地文件夹用于存储数据文件
21
- dataset_dir = Path("my_dataset")
22
- dataset_dir.mkdir(parents=True, exist_ok=True)
23
-
24
- # 初始化 CommitScheduler
25
- scheduler = CommitScheduler(
26
- repo_id="stabletoolbench/StableToolBench_data", # 替换为你的用户名和数据集仓库名
27
- repo_type="dataset",
28
- folder_path=dataset_dir,
29
- path_in_repo="",
30
- )
31
-
32
- # 根据排名生成表格数据
33
- def generate_table(data):
34
- if not data:
35
- return [], [] # No data, return empty headers and rows
36
-
37
- # Make sure all entries have a 'Scores' dictionary
38
- valid_data = [entry for entry in data if 'Scores' in entry and isinstance(entry['Scores'], dict)]
39
-
40
- # Sort the data based on the 'Average' score in descending order
41
- sorted_data = sorted(valid_data, key=lambda x: x['Scores'].get('Average', 0), reverse=True)
42
-
43
- # Now, build the table rows with the sorted data
44
- headers = ["Method"] + list(sorted_data[0]['Scores'].keys()) if sorted_data else ["Method"]
45
- rows = []
46
- for entry in sorted_data:
47
- row = [entry['Method']] + [entry['Scores'].get(key, "N/A") for key in headers[1:]]
48
- rows.append(row)
49
-
50
- return headers, rows
51
-
52
- # 原始数据
53
- 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)"]
54
-
55
- # 合并上传的数据到已有的数据中
56
- def merge_data(uploaded_data_json):
57
- # No need to call json.loads here because uploaded_data is already a Python dict
58
- new_data = uploaded_data_json
59
- with scheduler.lock: # 确保文件操作的线程安全
60
- # Define a helper function to merge scores for an entry
61
- def merge_scores(existing_scores, new_scores):
62
- for key, value in new_scores.items():
63
- existing_scores[key] = value
64
-
65
- # Merge 'SolvablePassRateScores'
66
- for new_entry in new_data["SolvablePassRateScores"]:
67
- if new_entry["Method"] not in protected_methods:
68
- existing_entry = next(
69
- (item for item in existing_data["SolvablePassRateScores"] if item["Method"] == new_entry["Method"]),
70
- None)
71
- if existing_entry:
72
- # 这是一个非保护的方法,更新它
73
- merge_scores(existing_entry["Scores"], new_entry["Scores"])
74
- else:
75
- # 这是一个新的方法,添加到列表中
76
- existing_data["SolvablePassRateScores"].append(new_entry)
77
-
78
- # Merge 'SolvableWinRateScores'
79
- for new_entry in new_data["SolvableWinRateScores"]:
80
- if new_entry["Method"] not in protected_methods:
81
- existing_entry = next(
82
- (item for item in existing_data["SolvableWinRateScores"] if item["Method"] == new_entry["Method"]),
83
- None)
84
- if existing_entry:
85
- merge_scores(existing_entry["Scores"], new_entry["Scores"])
86
- else:
87
- existing_data["SolvableWinRateScores"].append(new_entry)
88
-
89
- data_file_path = dataset_dir / "leaderboard_data.json"
90
- with open(data_file_path, 'w') as file:
91
- json.dump(existing_data, file, indent=4)
92
-
93
- # No need to sort here since we're doing it in the generate_table function
94
- return existing_data
95
-
96
- def process_file(file_info):
97
- if file_info is not None:
98
- # 如果 file_info 是文件的路径字符串,需要使用 'open' 来读取文件
99
- with open(file_info, "r") as uploaded_file:
100
- data_content = uploaded_file.read()
101
- uploaded_data_json = json.loads(data_content)
102
- # Merge the uploaded data
103
- merge_data(uploaded_data_json)
104
- scheduler.commit() # Trigger manual commit after processing
105
- # If we don't return anything here, gradio will not update the table
106
- # We need to return the new data for the table if it's interactive
107
- pass_rate_table = generate_table(existing_data["SolvablePassRateScores"])[1]
108
- win_rate_table = generate_table(existing_data["SolvableWinRateScores"])[1]
109
- return pass_rate_table, win_rate_table
110
-
111
- def refresh_table_data():
112
- # 重新加载数据
113
- new_data = existing_data
114
- # 重新生成表格数据
115
- new_pass_rate_data = generate_table(new_data["SolvablePassRateScores"])[1]
116
- new_win_rate_data = generate_table(new_data["SolvableWinRateScores"])[1]
117
- # 返回新的表格数据
118
- return new_pass_rate_data, new_win_rate_data
119
-
120
- # 创建界面
121
- with gr.Blocks() as app:
122
- # The large title
123
- gr.Markdown("# StableToolBench Leaderboard")
124
-
125
- # The introductory content
126
- gr.Markdown("""
127
- **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.
128
- """)
129
- gr.Markdown(""" ### For further information, please refer to: """)
130
- buttons_html = """
131
- <style>
132
- .custom-link-button {
133
- font-size: 18px !important; /* Adjust the font size as needed */
134
- padding: 10px 15px !important; /* Add some padding */
135
- margin: 5px !important;
136
- color: white !important; /* Text color */
137
- background-color: #106BA3 !important; /* Background color */
138
- text-decoration: none !important; /* Remove underline from links */
139
- display: inline-block !important;
140
- border-radius: 5px !important; /* Rounded corners */
141
- border: none !important; /* Remove borders */
142
- cursor: pointer !important; /* Mouse pointer on hover */
143
- text-align: center !important;
144
- }
145
- .custom-link-button:hover {
146
- background-color: #0D5B8F !important;
147
- }
148
- </style>
149
- <a href="https://arxiv.org/pdf/2403.07714.pdf" target="_blank" class="custom-link-button">Paper</a>
150
- <a href="https://arxiv.org/abs/2403.07714" target="_blank" class="custom-link-button">arXiv</a>
151
- <a href="https://github.com/zhichengg/StableToolBench" target="_blank" class="custom-link-button">Code</a>
152
- <a href="https://drive.google.com/file/d/1XUiCMA5NV359UGR-eknF0TcXORuR7RXj/view?pli=1" target="_blank" class="custom-link-button">Cache Data</a>
153
- """
154
-
155
- gr.HTML(buttons_html)
156
-
157
- # Markdown 标题
158
- gr.Markdown("## Solvable Pass Rate Scores")
159
- # 初始生成表格数据
160
- headers1, rows1 = generate_table(existing_data["SolvablePassRateScores"])
161
- table1 = gr.Dataframe(headers=headers1, value=rows1, interactive=False)
162
-
163
- gr.Markdown("## Solvable Win Rate Scores")
164
- # 初始生成表格数据
165
- headers2, rows2 = generate_table(existing_data["SolvableWinRateScores"])
166
- table2 = gr.Dataframe(headers=headers2, value=rows2, interactive=False)
167
-
168
- refresh_button = gr.Button("Refresh Leaderboards")
169
- # 当刷新按钮被点击时,调用 refresh_table_data 函数来更新表格
170
- refresh_button.click(
171
- fn=refresh_table_data,
172
- outputs=[table1, table2]
173
- )
174
-
175
- gr.Markdown("## Upload Your Own Results")
176
- gr.Markdown("""
177
- If you would like to contribute to the leaderboard, please follow the JSON structure below for your method's scores.
178
-
179
- **Solvable Pass Rate Scores Template:**
180
- ```json
181
- {
182
- "SolvablePassRateScores": [
183
- {
184
- "Method": "Your Method Name",
185
- "Scores": {
186
- "I1 Instruction": 85.5,
187
- "I1 Instruction SE": 1.2,
188
- "I1 Category": 80.0,
189
- "I1 Category SE": 1.0,
190
- "I1 Tool": 88.5,
191
- "I1 Tool SE": 0.8,
192
- "I2 Category": 82.5,
193
- "I2 Category SE": 1.3,
194
- "I2 Instruction": 86.0,
195
- "I2 Instruction SE": 0.5,
196
- "I3 Instruction": 90.0,
197
- "I3 Instruction SE": 0.7,
198
- "Average": 87.5,
199
- "Average SE": 1.1
200
- }
201
- }
202
- // Add more methods here...
203
- ],
204
- "SolvableWinRateScores": [
205
- {
206
- "Method": "Your Method Name",
207
- "Scores": {
208
- "I1 Instruction": 65.0,
209
- "I1 Category": 68.5,
210
- "I1 Tool": 66.8,
211
- "I2 Category": 70.0,
212
- "I2 Instruction": 69.2,
213
- "I3 Instruction": 71.5,
214
- "Average": 68.5
215
- }
216
- }
217
- // Add more methods here...
218
- ]
219
- }
220
- ```
221
-
222
- Make sure your uploaded JSON file follows this structure.
223
- """)
224
- # 文件上传组件和提交按钮
225
- upload_component = gr.File(label="Upload JSON File")
226
- submit_button = gr.Button("Submit")
227
-
228
- submit_button.click(
229
- fn=process_file,
230
- inputs=upload_component,
231
- outputs=[table1, table2]
232
- )
233
-
234
- # 引用部分
235
- gr.Markdown(" ## If you like our project, please consider cite our work as follows: ")
236
- citation_text = """
237
- ```
238
- @misc{guo2024stabletoolbench,
239
- title={StableToolBench: Towards Stable Large-Scale Benchmarking on Tool Learning of Large Language Models},
240
- 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},
241
- year={2024},
242
- eprint={2403.07714},
243
- archivePrefix={arXiv},
244
- primaryClass={cs.CL}
245
- }
246
- ```
247
- """
248
- gr.Markdown(citation_text)
249
-
250
- if __name__ == "__main__":
251
- app.launch()
252
- scheduler.commit() # Ensure all changes are committed on exit