Spaces:
Runtime error
Runtime error
File size: 7,872 Bytes
f417250 b66f230 f417250 23931c3 bbb5601 23931c3 b66f230 f417250 b66f230 f417250 b66f230 49d6897 b66f230 f417250 b66f230 f417250 b66f230 d79886f b66f230 f417250 b66f230 cdc057d f417250 23931c3 b66f230 23931c3 49d6897 bbb5601 2c5fd3f bbb5601 2c5fd3f f417250 2c5fd3f 49d6897 b66f230 49d6897 23931c3 2c5fd3f b66f230 49d6897 b66f230 2c5fd3f b66f230 23931c3 b66f230 2c5fd3f b66f230 23931c3 b66f230 2c5fd3f b66f230 2c5fd3f b66f230 2c5fd3f 23931c3 b66f230 bbb5601 b66f230 2c5fd3f b66f230 23931c3 b66f230 cdc057d 23931c3 b66f230 23931c3 b66f230 23931c3 b66f230 bbb5601 2c5fd3f bbb5601 |
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 |
import os
import gradio as gr
import pandas as pd
from gradio.themes.utils.sizes import text_md
from gradio_modal import Modal
from content import (HEADER_MARKDOWN, LEADERBOARD_TAB_TITLE_MARKDOWN, SUBMISSION_TAB_TITLE_MARKDOWN,
MODAL_SUBMIT_MARKDOWN,
SUBMISSION_DETAILS_MARKDOWN, RANKING_AFTER_SUBMISSION_MARKDOWN, MORE_DETAILS_MARKDOWN)
from server import LeaderboardServer
leaderboard_server = LeaderboardServer()
def on_submit_pressed():
return gr.update(value='Processing submission...', interactive=False)
def validate_submission_inputs(team_name, submission_id, link_to_model, submission_file):
if not team_name or not submission_id or not link_to_model or not submission_file:
raise ValueError('Please fill in all fields')
if not os.path.exists(submission_file):
raise ValueError('File does not exist')
def process_submission(team_name, submission_id, description, link_to_model, submission_file):
try:
validate_submission_inputs(team_name, submission_id, link_to_model, submission_file)
metadata = {
"team_name": team_name,
"submission_id": submission_id,
"description": description,
"link_to_model": link_to_model,
}
gr.Info('Submission valid, running local tournament...')
leaderboard_server.prepare_model_for_submission(submission_file, metadata)
except ValueError as err:
gr.Warning(str(err))
return gr.update(value='Pre-submit model', visible=True, interactive=True), gr.update(
visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(
visible=False), gr.update(visible=False)
return gr.update(visible=False), gr.update(visible=True), gr.update(interactive=True,
visible=True), gr.update(
interactive=True, visible=True), gr.update(visible=True), gr.update(
value=leaderboard_server.get_leaderboard(leaderboard_server.pre_submit[0]), visible=True)
def submit_results():
leaderboard_server.save_pre_submit()
leaderboard_server.update_leaderboard()
gr.Info('Submission successful!')
return gr.update(value='Pre-submit model', visible=True, interactive=True), gr.update(
visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(
visible=False), gr.update(visible=False), gr.DataFrame(
value=leaderboard_server.get_leaderboard(), visible=True), gr.update(visible=False), gr.update(
choices=leaderboard_server.submission_ids)
def erase_pre_submit():
leaderboard_server.pre_submit = None
return gr.update(value='Pre-submit model', visible=True, interactive=True), gr.update(
visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(
visible=False), gr.update(visible=False), gr.update(visible=False)
def fetch_model_detail(submission_id):
metadata = leaderboard_server.get_model_detail(submission_id)
return gr.update(value=metadata['description'], visible=True), gr.update(value=metadata['link_to_model'],
visible=True)
def show_modal():
return gr.update(visible=True)
def hide_modal():
return gr.update(visible=False)
def on_application_load():
leaderboard_server.save_pre_submit()
leaderboard_server.update_leaderboard()
return gr.DataFrame(
value=leaderboard_server.get_leaderboard(), visible=True), gr.update(
choices=leaderboard_server.submission_ids)
with (gr.Blocks(theme=gr.themes.Soft(text_size=text_md), css="footer {visibility: hidden}") as main):
with gr.Row():
with gr.Row():
gr.Markdown(HEADER_MARKDOWN)
with gr.Row():
with gr.Tab('Leaderboard') as leaderboards_tab:
gr.Markdown(LEADERBOARD_TAB_TITLE_MARKDOWN)
results_table = gr.DataFrame(leaderboard_server.get_leaderboard(), interactive=False, label=None,
visible=True)
gr.Markdown(MORE_DETAILS_MARKDOWN)
detail_dropdown = gr.Dropdown(choices=leaderboard_server.submission_ids, label="Select model",
interactive=True)
with gr.Row():
model_description = gr.Text(value='', label='Model description', visible=False, interactive=False)
model_url = gr.Text(value='', label='Model url', visible=False, interactive=False)
detail_dropdown.change(
fn=fetch_model_detail,
inputs=[detail_dropdown],
outputs=[model_description, model_url])
with gr.Tab('Submission'):
with gr.Column():
gr.Markdown(SUBMISSION_TAB_TITLE_MARKDOWN)
with gr.Row():
submission_team_name_tb = gr.Textbox(label='Team Name')
submission_id_tb = gr.Textbox(label='Submission ID')
with gr.Row():
description_tb = gr.Textbox(label='Description', type='text')
link_to_model_tb = gr.Textbox(label='Link to model', type='text')
submission_file_path = gr.File(label='Upload your results', type='filepath')
pre_submission_btn = gr.Button(value='Pre-submit model', interactive=True)
submit_prompt = gr.Markdown(
SUBMISSION_DETAILS_MARKDOWN,
visible=False
)
pre_submit_info = gr.Markdown(
RANKING_AFTER_SUBMISSION_MARKDOWN,
visible=False
)
pre_submit_table = gr.DataFrame(pd.DataFrame(), interactive=False, label=None, visible=False)
submission_btn_yes = gr.Button(value='Submit model', interactive=False, visible=False)
submission_btn_no = gr.Button(value='Reverse process', interactive=False, visible=False)
with Modal(visible=False) as modal_submit:
gr.Markdown(MODAL_SUBMIT_MARKDOWN)
modal_submit_yes = gr.Button("Yes", interactive=True)
modal_submit_no = gr.Button("No", interactive=True)
pre_submission_btn.click(
fn=on_submit_pressed,
concurrency_limit=1,
outputs=[pre_submission_btn]
).then(
fn=process_submission,
inputs=[submission_team_name_tb, submission_id_tb, description_tb, link_to_model_tb,
submission_file_path],
outputs=[pre_submission_btn, submit_prompt, submission_btn_yes, submission_btn_no, pre_submit_info,
pre_submit_table]
)
submission_btn_yes.click(
fn=show_modal,
outputs=[modal_submit]
)
modal_submit_yes.click(
fn=submit_results,
outputs=[pre_submission_btn, submission_btn_yes, submission_btn_no, submit_prompt, pre_submit_info,
pre_submit_table, results_table, modal_submit, detail_dropdown]
)
modal_submit_no.click(
fn=hide_modal,
outputs=[modal_submit]
)
submission_btn_no.click(
fn=erase_pre_submit,
outputs=[pre_submission_btn, submission_btn_yes, submission_btn_no, submit_prompt, pre_submit_info,
pre_submit_table]
)
main.load(on_application_load, inputs=None, outputs=[results_table, detail_dropdown])
main.launch()
|