Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -84,209 +84,208 @@ MAX_SUBMISSIONS_PER_24H = 2
|
|
84 |
# CHALLENGE_NAME = 'NOTSOFAR1'
|
85 |
|
86 |
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
with gr.Row():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
with gr.Row():
|
102 |
-
gr.Markdown(
|
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 |
with gr.Row():
|
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 |
-
with gr.Row():
|
223 |
-
hf_token_tb = gr.Textbox(label='Token', type='password')
|
224 |
-
submissions_24h_txt = gr.Textbox(label='Submissions 24h', value='')
|
225 |
-
description_tb = gr.Textbox(label='Description', type='text')
|
226 |
-
submission_btn = gr.Button(value='Submit', interactive=True)
|
227 |
-
gr.Markdown('### * Please make sure you are using NOTSOFAR dev-set-2 for your submissions')
|
228 |
-
|
229 |
-
submission_btn.click(
|
230 |
-
fn=on_submit_pressed,
|
231 |
-
outputs=[submission_btn]
|
232 |
-
).then(
|
233 |
-
fn=process_submission,
|
234 |
-
inputs=[submission_team_name_tb, submission_file_path,
|
235 |
-
submission_type_radio, description_tb, app_state]
|
236 |
-
).then(
|
237 |
-
fn=on_submit_done,
|
238 |
-
outputs=[submission_btn]
|
239 |
-
).then(
|
240 |
-
fn=on_dropdown_change,
|
241 |
-
outputs=[leaderboards_tabs, leaderboard_tables_list[0]]
|
242 |
-
)
|
243 |
-
|
244 |
-
# # My Submissions Tab #
|
245 |
-
# ######################
|
246 |
-
# with gr.Tab('My Submissions') as my_submissions_tab:
|
247 |
-
# def on_my_submissions_tab_select(app_state):
|
248 |
-
# hf_token = app_state.get('hf_token')
|
249 |
-
# if not hf_token:
|
250 |
-
# return pd.DataFrame(columns=['Please insert your Hugging Face token'])
|
251 |
-
# # submissions = lb_server.get_submissions_by_hf_token(hf_token=hf_token)
|
252 |
-
# # if submissions.empty:
|
253 |
-
# # submissions = pd.DataFrame(columns=['No submissions yet'])
|
254 |
-
# # return submissions
|
255 |
-
#
|
256 |
-
# gr.Markdown(MY_SUBMISSIONS_TAB_TITLE_MARKDOWN)
|
257 |
-
# my_submissions_table = gr.DataFrame()
|
258 |
-
#
|
259 |
-
# my_submissions_tab.select(fn=on_my_submissions_tab_select, inputs=[app_state],
|
260 |
-
# outputs=[my_submissions_table])
|
261 |
-
# my_submissions_token_tb = gr.Textbox(label='Token', type='password')
|
262 |
-
|
263 |
-
def on_token_insert(hf_token, app_state):
|
264 |
-
gr.Info(f'Verifying token...')
|
265 |
-
|
266 |
-
submission_count = None
|
267 |
-
# if hf_token:
|
268 |
-
# submission_count = lb_server.get_submission_count_last_24_hours(hf_token=hf_token)
|
269 |
-
|
270 |
-
if submission_count is None:
|
271 |
-
# Invalid token
|
272 |
-
app_state['hf_token'] = None
|
273 |
-
submissions_24h_str = ''
|
274 |
-
team_submissions_df = pd.DataFrame(columns=['Invalid Token'])
|
275 |
-
gr.Warning('Invalid token')
|
276 |
-
|
277 |
-
# else:
|
278 |
-
# app_state['hf_token'] = hf_token
|
279 |
-
# submissions_24h_str = f'{submission_count}/{MAX_SUBMISSIONS_PER_24H}'
|
280 |
-
# team_submissions_df = lb_server.get_submissions_by_hf_token(hf_token=hf_token)
|
281 |
-
# if team_submissions_df.empty:
|
282 |
-
# team_submissions_df = pd.DataFrame(columns=['No submissions yet'])
|
283 |
-
# gr.Info('Token verified!')
|
284 |
-
|
285 |
-
return app_state, team_submissions_df, submissions_24h_str
|
286 |
-
|
287 |
-
hf_token_tb.change(fn=on_token_insert, inputs=[hf_token_tb, app_state],
|
288 |
-
outputs=[app_state, submissions_24h_txt])
|
289 |
-
# my_submissions_token_tb.change(fn=on_token_insert, inputs=[my_submissions_token_tb, app_state],
|
290 |
-
# outputs=[app_state, my_submissions_table, submissions_24h_txt])
|
291 |
-
|
292 |
-
main.launch()
|
|
|
84 |
# CHALLENGE_NAME = 'NOTSOFAR1'
|
85 |
|
86 |
|
87 |
+
with (gr.Blocks(theme=gr.themes.Soft(text_size=text_md), css="footer {visibility: hidden}") as main):
|
88 |
+
app_state = gr.State({})
|
89 |
+
# with gr.Row():
|
90 |
+
# greet_name = gr.Textbox(label="Name")
|
91 |
+
# greet_output = gr.Textbox(label="Greetings")
|
92 |
+
# greet_btn = gr.Button("Greet")
|
93 |
+
# greet_btn.click(fn=greet, inputs=greet_name, outputs=greet_output).success(
|
94 |
+
# fn=save_json,
|
95 |
+
# inputs=[greet_name, greet_output],
|
96 |
+
# outputs=None,
|
97 |
+
# )
|
98 |
+
|
99 |
+
with gr.Row():
|
100 |
with gr.Row():
|
101 |
+
gr.Markdown(HEADER_MARKDOWN)
|
102 |
+
|
103 |
+
with gr.Row():
|
104 |
+
|
105 |
+
# Leaderboards Tab #
|
106 |
+
####################
|
107 |
+
def populate_leaderboard(leaderboard_type, dataset_version):
|
108 |
+
gr.Info('Loading leaderboard...')
|
109 |
+
time.sleep(1)
|
110 |
+
leaderboard_df = leaderboard_server.get_leaderboard()
|
111 |
+
# leaderboard_df = lb_server.get_leaderboard(
|
112 |
+
# submission_type=leaderboard_type, dataset_version=dataset_version)
|
113 |
+
# if leaderboard_df.empty:
|
114 |
+
return leaderboard_df
|
115 |
+
# return leaderboard_df
|
116 |
+
|
117 |
+
|
118 |
+
def create_leaderboard_tab(tab_name: str, idx: int, dataset_version_dropdown: gr.Dropdown):
|
119 |
+
# dataset_version = dataset_version_dropdown.value
|
120 |
+
print(f'Creating tab for {tab_name}, idx={idx}, dataset_version={dataset_version_dropdown}')
|
121 |
+
with gr.Tab(id=tab_name, label=tab_name) as leaderboard_tab:
|
122 |
+
leaderboard_table = gr.DataFrame(populate_leaderboard(tab_name, None)) if idx == 0 \
|
123 |
+
else gr.DataFrame(pd.DataFrame(columns=['No submissions yet']))
|
124 |
+
leaderboard_tab.select(fn=populate_leaderboard,
|
125 |
+
inputs=[gr.Text(tab_name, visible=False)],
|
126 |
+
outputs=[leaderboard_table])
|
127 |
+
return leaderboard_table
|
128 |
+
|
129 |
+
def on_dropdown_change():
|
130 |
+
first_tab_name = LEADERBOARD_TYPES[0]
|
131 |
+
leaderboard_server.on_submit()
|
132 |
+
|
133 |
+
return gr.Tabs(selected=first_tab_name), populate_leaderboard(first_tab_name, None)
|
134 |
+
|
135 |
+
|
136 |
+
with gr.Tab('Leaderboards') as leaderboards_tab:
|
137 |
with gr.Row():
|
138 |
+
gr.Markdown(LEADERBOARD_TAB_TITLE_MARKDOWN)
|
139 |
+
# with gr.Row():
|
140 |
+
# with gr.Column():
|
141 |
+
# dataset_version_drop = gr.Dropdown(choices=DATASET_VERSIONS, multiselect=False,
|
142 |
+
# value=DATASET_VERSIONS[-1], label="Dataset",
|
143 |
+
# interactive=True)
|
144 |
+
# with gr.Column():
|
145 |
+
# gr.Markdown('') # Empty column for spacing
|
146 |
+
# with gr.Column():
|
147 |
+
# gr.Markdown('') # Empty column for spacing
|
148 |
+
# with gr.Column():
|
149 |
+
# gr.Markdown('') # Empty column for spacing
|
150 |
+
with gr.Row():
|
151 |
+
with gr.Tabs() as leaderboards_tabs:
|
152 |
+
leaderboard_tables_list = []
|
153 |
+
for leaderboard_idx, leaderboard_type in enumerate(LEADERBOARD_TYPES):
|
154 |
+
l_tab = create_leaderboard_tab(leaderboard_type, leaderboard_idx, None)
|
155 |
+
leaderboard_tables_list.append(l_tab)
|
156 |
+
|
157 |
+
# dataset_version_drop.select(fn=on_dropdown_change, inputs=[dataset_version_drop],
|
158 |
+
# outputs=[leaderboards_tabs, leaderboard_tables_list[0]])
|
159 |
+
|
160 |
+
|
161 |
+
# Submission Tab #
|
162 |
+
##################
|
163 |
+
with gr.Tab('Submission'):
|
164 |
+
with gr.Column():
|
165 |
+
def on_submit_pressed():
|
166 |
+
return gr.update(value='Processing submission...', interactive=False)
|
167 |
+
|
168 |
+
def validate_submission_inputs(team_name, submission_zip, submission_type, token):
|
169 |
+
if not team_name or not submission_zip or not submission_type:
|
170 |
+
raise ValueError('Please fill in all fields')
|
171 |
+
if not os.path.exists(submission_zip):
|
172 |
+
raise ValueError('File does not exist')
|
173 |
+
# if not submission_zip.endswith('.zip'):
|
174 |
+
# raise ValueError('File must be a zip')
|
175 |
+
# if not token:
|
176 |
+
# raise ValueError('Please insert a valid Hugging Face token')
|
177 |
+
|
178 |
+
def process_submission(team_name, submission, submission_type, description,
|
179 |
+
app_state, request: gr.Request):
|
180 |
+
logging.info(f'{team_name}: new submission for track: {submission_type}')
|
181 |
+
try:
|
182 |
+
token = app_state.get('hf_token')
|
183 |
+
validate_submission_inputs(team_name, submission, submission_type, token)
|
184 |
+
except ValueError as err:
|
185 |
+
gr.Warning(str(err))
|
186 |
+
return
|
187 |
+
|
188 |
+
|
189 |
+
# metadata = {'challenge_name': CHALLENGE_NAME,
|
190 |
+
# "dataset_version": DATASET_VERSIONS[-1],
|
191 |
+
# 'team_name': team_name,
|
192 |
+
# 'submission_type': submission_type,
|
193 |
+
# 'description': description,
|
194 |
+
# 'token': token,
|
195 |
+
# 'file_name': os.path.basename(submission_zip),
|
196 |
+
# 'file_size_mb': os.path.getsize(submission_zip) / 1024 / 1024,
|
197 |
+
# 'ip': request.client.host}
|
198 |
+
leaderboard_server.save_json(submission)
|
199 |
+
|
200 |
+
try:
|
201 |
+
gr.Info('Processing submission...')
|
202 |
+
# response = lb_server.add_submission(token=token, file_path=submission_zip, metadata=metadata)
|
203 |
+
# if 'error' in response:
|
204 |
+
# gr.Warning(f'Failed to process submission - {response["error"]}')
|
205 |
+
# else:
|
206 |
+
gr.Info('Done processing submission')
|
207 |
+
except Exception as e:
|
208 |
+
gr.Warning(f'Submission failed to upload - {e}')
|
209 |
+
|
210 |
+
def on_submit_done():
|
211 |
+
on_dropdown_change()
|
212 |
+
leaderboard_server.on_submit()
|
213 |
+
# leaderboard_tab.children[0] = gr.DataFrame(populate_leaderboard(None, None))
|
214 |
+
# leaderboard_tab.render()
|
215 |
+
return gr.update(value='Submit', interactive=True)
|
216 |
+
|
217 |
+
gr.Markdown(SUBMISSION_TAB_TITLE_MARKDOWN)
|
218 |
+
submission_team_name_tb = gr.Textbox(label='Team Name')
|
219 |
+
submission_file_path = gr.File(label='Upload your results', type='filepath')
|
220 |
+
submission_type_radio = gr.Radio(label='Submission Track', choices=LEADERBOARD_TYPES)
|
221 |
with gr.Row():
|
222 |
+
hf_token_tb = gr.Textbox(label='Token', type='password')
|
223 |
+
submissions_24h_txt = gr.Textbox(label='Submissions 24h', value='')
|
224 |
+
description_tb = gr.Textbox(label='Description', type='text')
|
225 |
+
submission_btn = gr.Button(value='Submit', interactive=True)
|
226 |
+
gr.Markdown('### * Please make sure you are using NOTSOFAR dev-set-2 for your submissions')
|
227 |
+
|
228 |
+
submission_btn.click(
|
229 |
+
fn=on_submit_pressed,
|
230 |
+
outputs=[submission_btn]
|
231 |
+
).then(
|
232 |
+
fn=process_submission,
|
233 |
+
inputs=[submission_team_name_tb, submission_file_path,
|
234 |
+
submission_type_radio, description_tb, app_state]
|
235 |
+
).then(
|
236 |
+
fn=on_submit_done,
|
237 |
+
outputs=[submission_btn]
|
238 |
+
).then(
|
239 |
+
fn=on_dropdown_change,
|
240 |
+
outputs=[leaderboards_tabs, leaderboard_tables_list[0]]
|
241 |
+
)
|
242 |
+
|
243 |
+
# # My Submissions Tab #
|
244 |
+
# ######################
|
245 |
+
# with gr.Tab('My Submissions') as my_submissions_tab:
|
246 |
+
# def on_my_submissions_tab_select(app_state):
|
247 |
+
# hf_token = app_state.get('hf_token')
|
248 |
+
# if not hf_token:
|
249 |
+
# return pd.DataFrame(columns=['Please insert your Hugging Face token'])
|
250 |
+
# # submissions = lb_server.get_submissions_by_hf_token(hf_token=hf_token)
|
251 |
+
# # if submissions.empty:
|
252 |
+
# # submissions = pd.DataFrame(columns=['No submissions yet'])
|
253 |
+
# # return submissions
|
254 |
+
#
|
255 |
+
# gr.Markdown(MY_SUBMISSIONS_TAB_TITLE_MARKDOWN)
|
256 |
+
# my_submissions_table = gr.DataFrame()
|
257 |
+
#
|
258 |
+
# my_submissions_tab.select(fn=on_my_submissions_tab_select, inputs=[app_state],
|
259 |
+
# outputs=[my_submissions_table])
|
260 |
+
# my_submissions_token_tb = gr.Textbox(label='Token', type='password')
|
261 |
+
|
262 |
+
def on_token_insert(hf_token, app_state):
|
263 |
+
gr.Info(f'Verifying token...')
|
264 |
+
|
265 |
+
submission_count = None
|
266 |
+
# if hf_token:
|
267 |
+
# submission_count = lb_server.get_submission_count_last_24_hours(hf_token=hf_token)
|
268 |
+
|
269 |
+
if submission_count is None:
|
270 |
+
# Invalid token
|
271 |
+
app_state['hf_token'] = None
|
272 |
+
submissions_24h_str = ''
|
273 |
+
team_submissions_df = pd.DataFrame(columns=['Invalid Token'])
|
274 |
+
gr.Warning('Invalid token')
|
275 |
+
|
276 |
+
# else:
|
277 |
+
# app_state['hf_token'] = hf_token
|
278 |
+
# submissions_24h_str = f'{submission_count}/{MAX_SUBMISSIONS_PER_24H}'
|
279 |
+
# team_submissions_df = lb_server.get_submissions_by_hf_token(hf_token=hf_token)
|
280 |
+
# if team_submissions_df.empty:
|
281 |
+
# team_submissions_df = pd.DataFrame(columns=['No submissions yet'])
|
282 |
+
# gr.Info('Token verified!')
|
283 |
+
|
284 |
+
return app_state, team_submissions_df, submissions_24h_str
|
285 |
+
|
286 |
+
hf_token_tb.change(fn=on_token_insert, inputs=[hf_token_tb, app_state],
|
287 |
+
outputs=[app_state, submissions_24h_txt])
|
288 |
+
# my_submissions_token_tb.change(fn=on_token_insert, inputs=[my_submissions_token_tb, app_state],
|
289 |
+
# outputs=[app_state, my_submissions_table, submissions_24h_txt])
|
290 |
+
|
291 |
+
main.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|