Lakoc commited on
Commit
f417250
β€’
1 Parent(s): 66c1268

initial_commit

Browse files
Files changed (3) hide show
  1. app.py +290 -0
  2. content.py +56 -0
  3. requirements.txt +7 -0
app.py ADDED
@@ -0,0 +1,290 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import glob
2
+ import os
3
+ import logging
4
+
5
+ import pandas as pd
6
+ import gradio as gr
7
+ from gradio.themes.utils.sizes import text_md
8
+
9
+ from content import (HEADER_MARKDOWN, LEADERBOARD_TAB_TITLE_MARKDOWN, SUBMISSION_TAB_TITLE_MARKDOWN,
10
+ )
11
+
12
+ import json
13
+ from datetime import datetime
14
+ from pathlib import Path
15
+ from uuid import uuid4
16
+ import time
17
+ import gradio as gr
18
+
19
+ from huggingface_hub import HfApi, snapshot_download
20
+
21
+
22
+ JSON_DATASET_DIR = Path("../json_dataset")
23
+ JSON_DATASET_DIR.mkdir(parents=True, exist_ok=True)
24
+
25
+ JSON_DATASET_PATH = JSON_DATASET_DIR / f"train-{uuid4()}.json"
26
+
27
+
28
+ api = HfApi()
29
+
30
+ ORG= "CZLC"
31
+ REPO = f"{ORG}/LLM_benchmark_data"
32
+
33
+ def greet(name: str) -> str:
34
+ return "Hello " + name + "!"
35
+
36
+
37
+ DATASET_VERSIONS = ['dev-set-1', 'dev-set-2']
38
+
39
+
40
+
41
+
42
+ class LeaderboardServer:
43
+ def __init__(self, server_address):
44
+ self.server_address = server_address
45
+ self.repo_type = "dataset"
46
+ self.local_leaderboard = snapshot_download(self.server_address,repo_type=self.repo_type)
47
+
48
+ def on_submit(self):
49
+ self.local_leaderboard = snapshot_download(self.server_address,repo_type=self.repo_type)
50
+
51
+ def get_leaderboard(self):
52
+ results = []
53
+ for submission in glob.glob(os.path.join(self.local_leaderboard, "../data") + "/*.json"):
54
+ data = json.load(open(submission))
55
+ submission_id = data["metadata"]["model_description"]
56
+ local_results = {group: data["results"][group]['acc'] for group in data['results']}
57
+ local_results["submission_id"] = submission_id
58
+ results.append(local_results)
59
+ dataframe = pd.DataFrame.from_records(results)
60
+ return dataframe
61
+
62
+ def save_json(self,file) -> None:
63
+ filename = os.path.basename(file)
64
+ api.upload_file(
65
+ path_or_fileobj=file,
66
+ path_in_repo=f"data/{filename}",
67
+ repo_id=self.server_address,
68
+ repo_type=self.repo_type
69
+ )
70
+
71
+
72
+
73
+ leaderboard_server = LeaderboardServer(REPO)
74
+
75
+
76
+ logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
77
+
78
+
79
+ LEADERBOARD_TYPES = ['LLM',]
80
+ MAX_SUBMISSIONS_PER_24H = 2
81
+ # DATASET_VERSIONS = ['dev-set-1', 'dev-set-2']
82
+ # CHALLENGE_NAME = 'NOTSOFAR1'
83
+
84
+
85
+ if __name__ == '__main__':
86
+ with (gr.Blocks(theme=gr.themes.Soft(text_size=text_md), css="footer {visibility: hidden}") as main):
87
+ app_state = gr.State({})
88
+ # with gr.Row():
89
+ # greet_name = gr.Textbox(label="Name")
90
+ # greet_output = gr.Textbox(label="Greetings")
91
+ # greet_btn = gr.Button("Greet")
92
+ # greet_btn.click(fn=greet, inputs=greet_name, outputs=greet_output).success(
93
+ # fn=save_json,
94
+ # inputs=[greet_name, greet_output],
95
+ # outputs=None,
96
+ # )
97
+
98
+ with gr.Row():
99
+ with gr.Row():
100
+ gr.Markdown(HEADER_MARKDOWN)
101
+
102
+ with gr.Row():
103
+
104
+ # Leaderboards Tab #
105
+ ####################
106
+ def populate_leaderboard(leaderboard_type, dataset_version):
107
+ gr.Info('Loading leaderboard...')
108
+ time.sleep(1)
109
+ leaderboard_df = leaderboard_server.get_leaderboard()
110
+ # leaderboard_df = lb_server.get_leaderboard(
111
+ # submission_type=leaderboard_type, dataset_version=dataset_version)
112
+ # if leaderboard_df.empty:
113
+ return leaderboard_df
114
+ # return leaderboard_df
115
+
116
+
117
+ def create_leaderboard_tab(tab_name: str, idx: int, dataset_version_dropdown: gr.Dropdown):
118
+ # dataset_version = dataset_version_dropdown.value
119
+ print(f'Creating tab for {tab_name}, idx={idx}, dataset_version={dataset_version_dropdown}')
120
+ with gr.Tab(id=tab_name, label=tab_name) as leaderboard_tab:
121
+ leaderboard_table = gr.DataFrame(populate_leaderboard(tab_name, None)) if idx == 0 \
122
+ else gr.DataFrame(pd.DataFrame(columns=['No submissions yet']))
123
+ leaderboard_tab.select(fn=populate_leaderboard,
124
+ inputs=[gr.Text(tab_name, visible=False)],
125
+ outputs=[leaderboard_table])
126
+ return leaderboard_table
127
+
128
+ def on_dropdown_change():
129
+ first_tab_name = LEADERBOARD_TYPES[0]
130
+ leaderboard_server.on_submit()
131
+
132
+ return gr.Tabs(selected=first_tab_name), populate_leaderboard(first_tab_name, None)
133
+
134
+
135
+ with gr.Tab('Leaderboards') as leaderboards_tab:
136
+ with gr.Row():
137
+ gr.Markdown(LEADERBOARD_TAB_TITLE_MARKDOWN)
138
+ # with gr.Row():
139
+ # with gr.Column():
140
+ # dataset_version_drop = gr.Dropdown(choices=DATASET_VERSIONS, multiselect=False,
141
+ # value=DATASET_VERSIONS[-1], label="Dataset",
142
+ # interactive=True)
143
+ # with gr.Column():
144
+ # gr.Markdown('') # Empty column for spacing
145
+ # with gr.Column():
146
+ # gr.Markdown('') # Empty column for spacing
147
+ # with gr.Column():
148
+ # gr.Markdown('') # Empty column for spacing
149
+ with gr.Row():
150
+ with gr.Tabs() as leaderboards_tabs:
151
+ leaderboard_tables_list = []
152
+ for leaderboard_idx, leaderboard_type in enumerate(LEADERBOARD_TYPES):
153
+ l_tab = create_leaderboard_tab(leaderboard_type, leaderboard_idx, None)
154
+ leaderboard_tables_list.append(l_tab)
155
+
156
+ # dataset_version_drop.select(fn=on_dropdown_change, inputs=[dataset_version_drop],
157
+ # outputs=[leaderboards_tabs, leaderboard_tables_list[0]])
158
+
159
+
160
+ # Submission Tab #
161
+ ##################
162
+ with gr.Tab('Submission'):
163
+ with gr.Column():
164
+ def on_submit_pressed():
165
+ return gr.update(value='Processing submission...', interactive=False)
166
+
167
+ def validate_submission_inputs(team_name, submission_zip, submission_type, token):
168
+ if not team_name or not submission_zip or not submission_type:
169
+ raise ValueError('Please fill in all fields')
170
+ if not os.path.exists(submission_zip):
171
+ raise ValueError('File does not exist')
172
+ # if not submission_zip.endswith('.zip'):
173
+ # raise ValueError('File must be a zip')
174
+ # if not token:
175
+ # raise ValueError('Please insert a valid Hugging Face token')
176
+
177
+ def process_submission(team_name, submission, submission_type, description,
178
+ app_state, request: gr.Request):
179
+ logging.info(f'{team_name}: new submission for track: {submission_type}')
180
+ try:
181
+ token = app_state.get('hf_token')
182
+ validate_submission_inputs(team_name, submission, submission_type, token)
183
+ except ValueError as err:
184
+ gr.Warning(str(err))
185
+ return
186
+
187
+
188
+ # metadata = {'challenge_name': CHALLENGE_NAME,
189
+ # "dataset_version": DATASET_VERSIONS[-1],
190
+ # 'team_name': team_name,
191
+ # 'submission_type': submission_type,
192
+ # 'description': description,
193
+ # 'token': token,
194
+ # 'file_name': os.path.basename(submission_zip),
195
+ # 'file_size_mb': os.path.getsize(submission_zip) / 1024 / 1024,
196
+ # 'ip': request.client.host}
197
+ leaderboard_server.save_json(submission)
198
+
199
+ try:
200
+ gr.Info('Processing submission...')
201
+ # response = lb_server.add_submission(token=token, file_path=submission_zip, metadata=metadata)
202
+ # if 'error' in response:
203
+ # gr.Warning(f'Failed to process submission - {response["error"]}')
204
+ # else:
205
+ gr.Info('Done processing submission')
206
+ except Exception as e:
207
+ gr.Warning(f'Submission failed to upload - {e}')
208
+
209
+ def on_submit_done():
210
+ on_dropdown_change()
211
+ leaderboard_server.on_submit()
212
+ # leaderboard_tab.children[0] = gr.DataFrame(populate_leaderboard(None, None))
213
+ # leaderboard_tab.render()
214
+ return gr.update(value='Submit', interactive=True)
215
+
216
+ gr.Markdown(SUBMISSION_TAB_TITLE_MARKDOWN)
217
+ submission_team_name_tb = gr.Textbox(label='Team Name')
218
+ submission_file_path = gr.File(label='Upload your results', type='filepath')
219
+ submission_type_radio = gr.Radio(label='Submission Track', choices=LEADERBOARD_TYPES)
220
+ with gr.Row():
221
+ hf_token_tb = gr.Textbox(label='Token', type='password')
222
+ submissions_24h_txt = gr.Textbox(label='Submissions 24h', value='')
223
+ description_tb = gr.Textbox(label='Description', type='text')
224
+ submission_btn = gr.Button(value='Submit', interactive=True)
225
+ gr.Markdown('### * Please make sure you are using NOTSOFAR dev-set-2 for your submissions')
226
+
227
+ submission_btn.click(
228
+ fn=on_submit_pressed,
229
+ outputs=[submission_btn]
230
+ ).then(
231
+ fn=process_submission,
232
+ inputs=[submission_team_name_tb, submission_file_path,
233
+ submission_type_radio, description_tb, app_state]
234
+ ).then(
235
+ fn=on_submit_done,
236
+ outputs=[submission_btn]
237
+ ).then(
238
+ fn=on_dropdown_change,
239
+ outputs=[leaderboards_tabs, leaderboard_tables_list[0]]
240
+ )
241
+
242
+ # # My Submissions Tab #
243
+ # ######################
244
+ # with gr.Tab('My Submissions') as my_submissions_tab:
245
+ # def on_my_submissions_tab_select(app_state):
246
+ # hf_token = app_state.get('hf_token')
247
+ # if not hf_token:
248
+ # return pd.DataFrame(columns=['Please insert your Hugging Face token'])
249
+ # # submissions = lb_server.get_submissions_by_hf_token(hf_token=hf_token)
250
+ # # if submissions.empty:
251
+ # # submissions = pd.DataFrame(columns=['No submissions yet'])
252
+ # # return submissions
253
+ #
254
+ # gr.Markdown(MY_SUBMISSIONS_TAB_TITLE_MARKDOWN)
255
+ # my_submissions_table = gr.DataFrame()
256
+ #
257
+ # my_submissions_tab.select(fn=on_my_submissions_tab_select, inputs=[app_state],
258
+ # outputs=[my_submissions_table])
259
+ # my_submissions_token_tb = gr.Textbox(label='Token', type='password')
260
+
261
+ def on_token_insert(hf_token, app_state):
262
+ gr.Info(f'Verifying token...')
263
+
264
+ submission_count = None
265
+ # if hf_token:
266
+ # submission_count = lb_server.get_submission_count_last_24_hours(hf_token=hf_token)
267
+
268
+ if submission_count is None:
269
+ # Invalid token
270
+ app_state['hf_token'] = None
271
+ submissions_24h_str = ''
272
+ team_submissions_df = pd.DataFrame(columns=['Invalid Token'])
273
+ gr.Warning('Invalid token')
274
+
275
+ # else:
276
+ # app_state['hf_token'] = hf_token
277
+ # submissions_24h_str = f'{submission_count}/{MAX_SUBMISSIONS_PER_24H}'
278
+ # team_submissions_df = lb_server.get_submissions_by_hf_token(hf_token=hf_token)
279
+ # if team_submissions_df.empty:
280
+ # team_submissions_df = pd.DataFrame(columns=['No submissions yet'])
281
+ # gr.Info('Token verified!')
282
+
283
+ return app_state, team_submissions_df, submissions_24h_str
284
+
285
+ hf_token_tb.change(fn=on_token_insert, inputs=[hf_token_tb, app_state],
286
+ outputs=[app_state, submissions_24h_txt])
287
+ # my_submissions_token_tb.change(fn=on_token_insert, inputs=[my_submissions_token_tb, app_state],
288
+ # outputs=[app_state, my_submissions_table, submissions_24h_txt])
289
+
290
+ main.launch()
content.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ This file contains the text content for the leaderboard client.
3
+ """
4
+
5
+
6
+ # HEADER_MARKDOWN = """
7
+ # # CHiME-8 Leaderboard
8
+ # In collaboration with the CHiME-8 Challenge, the NOTSOFAR team is proud to host the official leaderboard for the three tasks this year.\n
9
+ # For details, visit:
10
+ # 1. [DASR](https://www.chimechallenge.org/current/task1/index)
11
+ # 2. [NOTSOFAR](https://www.chimechallenge.org/current/task2/index)
12
+ # 3. [MMCSG](https://www.chimechallenge.org/current/task3/index)
13
+ #
14
+ #
15
+ # ### DASR and NOTSOFAR - the scientific story
16
+ # Both tasks focus on distant automatic speech recognition and speaker diarization, offering a fundamental comparison
17
+ # among different system designs:
18
+ # - Single-channel (SC), 1 device (NOTSOFAR-SC)
19
+ # - Multi-channel (MC), known-geometry, 1 device (NOTSOFAR-MC)
20
+ # - Multi-channel (MC), geometry-agnostic, multiple devices (DASR-Constrained-LM and DASR-Unconstrained-LM)
21
+ #
22
+ # Featured in both tasks, the NOTSOFAR recorded meeting dataset is leveraged as a common benchmark:
23
+ # each geometry-agnostic MC system submitted to DASR tracks (constrained or not) will also be **automatically submitted**
24
+ # to the known-geometry single-device NOTSOFAR-MC track. These entries will be marked with "DASR" to denote their origin.
25
+ # """
26
+ HEADER_MARKDOWN = """ """
27
+
28
+ LEADERBOARD_TAB_TITLE_MARKDOWN = """
29
+ ## Leaderboard
30
+ """
31
+
32
+
33
+ SUBMISSION_TAB_TITLE_MARKDOWN = """
34
+ ## Submission
35
+
36
+ To submit your results, please fill in the form below.
37
+
38
+ - *Team Name:* The name of your team, as it will appear on the leaderboard'
39
+ - *Results:* Results zip file to submit
40
+ - *Submission track:* The track to submit results to
41
+ - *Token:* Your Hugging Face token
42
+ - *Description:* Short description of your submission (optional)
43
+
44
+ **Hugging Face tokens:** To create a token, go to your profile settings > Access Tokens > New Token.
45
+ Name the token and give it a write role, then copy the token and paste it in the field below.
46
+
47
+ **Team creation:** Upon the first submission, your team name is associated with your Hugging Face user account.
48
+ Any token generated by your account can be used. All team members should use this specific user's token for
49
+ future submissions.
50
+
51
+ **Submission limit:** 5 submissions per team every 24 hours. Each participant should only belong to one team.
52
+ Changing team names is allowed, but it is not intended to bypass the daily submission limit.
53
+ """
54
+
55
+ SUBMISSION_TAB_TITLE_MARKDOWN = """
56
+ """
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ gradio
2
+ pandas
3
+ azure-cosmos
4
+ huggingface_hub
5
+ requests
6
+ Pyarrow
7
+ tabulate