chan030609's picture
First commit
6a190a4
raw
history blame
2.59 kB
import gradio as gr
import pandas as pd
import os
from apscheduler.schedulers.background import BackgroundScheduler
from huggingface_hub import HfApi
from uploads import add_new_eval
from utils import LEADERBOARD_PATH, CORPORA, load_data, DEFAULT_COLUMNS, DEFAULT_COLUMN_LABELS
CITATION_BUTTON_LABEL = "Copy the following snippet to cite these results."
api = HfApi()
TOKEN = os.environ.get("TOKEN", None)
def restart_space():
api.restart_space(repo_id=LEADERBOARD_PATH, token=TOKEN)
demo = gr.Blocks()
with demo:
with open("asset/p1.md", 'r') as f:
gr.Markdown(f.read())
with gr.Row():
with gr.Accordion("πŸ“™ Citation", open=False):
with open("asset/citation_button_text.txt", 'r') as f:
citation_button = gr.Textbox(
value=f.read(),
label="Copy the following snippet to cite these results:",
elem_id="citation-button",
show_copy_button=True,
)
with gr.Tabs():
with gr.TabItem("Leaderboard"):
with gr.Row():
corpus_dropdown = gr.Dropdown(
choices=CORPORA,
label="πŸ”„ Select corpus",
value=CORPORA[0],
)
leaderboard_table = gr.components.Dataframe(
value=load_data(CORPORA[0]),
interactive=True,
visible=True,
)
corpus_dropdown.change(
load_data,
inputs=[corpus_dropdown],
outputs=leaderboard_table
)
with gr.Accordion("Submit a new model for evaluation"):
with gr.Row():
with gr.Column():
corpus_radio = gr.Radio(['news', 'books'], value="llama", label="Corpus")
organization_textbox = gr.Textbox(label="Organization")
mail_textbox = gr.Textbox(label="Contact email")
with gr.Column():
file_output = gr.File()
submit_button = gr.Button("Submit Eval")
submission_result = gr.Markdown()
submit_button.click(
add_new_eval,
[
corpus_radio,
organization_textbox,
mail_textbox,
file_output
],
submission_result,
)
with open(f"asset/p2.md", 'r') as f:
gr.Markdown(f.read())
scheduler = BackgroundScheduler()
scheduler.add_job(restart_space, "interval", seconds=3600)
scheduler.start()
demo.launch(debug=True)