Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from gradio_leaderboard import Leaderboard, ColumnFilter, SelectColumns
|
| 3 |
import pandas as pd
|
| 4 |
from apscheduler.schedulers.background import BackgroundScheduler
|
| 5 |
-
from huggingface_hub import snapshot_download
|
| 6 |
|
| 7 |
from src.about import (
|
| 8 |
CITATION_BUTTON_LABEL,
|
|
@@ -26,8 +25,7 @@ from src.display.utils import (
|
|
| 26 |
)
|
| 27 |
from src.envs import API, EVAL_REQUESTS_PATH, EVAL_RESULTS_PATH, QUEUE_REPO, REPO_ID, RESULTS_REPO, TOKEN
|
| 28 |
from src.populate import get_evaluation_queue_df, get_leaderboard_df
|
| 29 |
-
from src.submission.submit import add_new_eval
|
| 30 |
-
|
| 31 |
|
| 32 |
def restart_space():
|
| 33 |
API.restart_space(repo_id=REPO_ID)
|
|
@@ -36,19 +34,29 @@ def restart_space():
|
|
| 36 |
try:
|
| 37 |
print(EVAL_REQUESTS_PATH)
|
| 38 |
snapshot_download(
|
| 39 |
-
repo_id=QUEUE_REPO,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
)
|
| 41 |
except Exception:
|
| 42 |
restart_space()
|
|
|
|
| 43 |
try:
|
| 44 |
print(EVAL_RESULTS_PATH)
|
| 45 |
snapshot_download(
|
| 46 |
-
repo_id=RESULTS_REPO,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
)
|
| 48 |
except Exception:
|
| 49 |
restart_space()
|
| 50 |
|
| 51 |
-
|
| 52 |
LEADERBOARD_DF = get_leaderboard_df(EVAL_RESULTS_PATH, EVAL_REQUESTS_PATH, COLS, BENCHMARK_COLS)
|
| 53 |
|
| 54 |
(
|
|
@@ -57,39 +65,21 @@ LEADERBOARD_DF = get_leaderboard_df(EVAL_RESULTS_PATH, EVAL_REQUESTS_PATH, COLS,
|
|
| 57 |
pending_eval_queue_df,
|
| 58 |
) = get_evaluation_queue_df(EVAL_REQUESTS_PATH, EVAL_COLS)
|
| 59 |
|
|
|
|
| 60 |
def init_leaderboard(dataframe):
|
| 61 |
if dataframe is None or dataframe.empty:
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
| 64 |
value=dataframe,
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
default_selection=[c.name for c in fields(AutoEvalColumn) if c.displayed_by_default],
|
| 68 |
-
cant_deselect=[c.name for c in fields(AutoEvalColumn) if c.never_hidden],
|
| 69 |
-
label="Select Columns to Display:",
|
| 70 |
-
),
|
| 71 |
-
search_columns=[AutoEvalColumn.model.name, AutoEvalColumn.license.name],
|
| 72 |
-
hide_columns=[c.name for c in fields(AutoEvalColumn) if c.hidden],
|
| 73 |
-
filter_columns=[
|
| 74 |
-
ColumnFilter(AutoEvalColumn.model_type.name, type="checkboxgroup", label="Model types"),
|
| 75 |
-
ColumnFilter(AutoEvalColumn.precision.name, type="checkboxgroup", label="Precision"),
|
| 76 |
-
ColumnFilter(
|
| 77 |
-
AutoEvalColumn.params.name,
|
| 78 |
-
type="slider",
|
| 79 |
-
min=0.01,
|
| 80 |
-
max=150,
|
| 81 |
-
label="Select the number of parameters (B)",
|
| 82 |
-
),
|
| 83 |
-
ColumnFilter(
|
| 84 |
-
AutoEvalColumn.still_on_hub.name, type="boolean", label="Deleted/incomplete", default=True
|
| 85 |
-
),
|
| 86 |
-
],
|
| 87 |
-
bool_checkboxgroup_label="Hide models",
|
| 88 |
interactive=False,
|
| 89 |
)
|
| 90 |
|
| 91 |
-
|
| 92 |
demo = gr.Blocks(css=custom_css)
|
|
|
|
| 93 |
with demo:
|
| 94 |
gr.HTML(TITLE)
|
| 95 |
gr.Markdown(INTRODUCTION_TEXT, elem_classes="markdown-text")
|
|
@@ -129,7 +119,6 @@ with demo:
|
|
| 129 |
datatype=EVAL_TYPES,
|
| 130 |
row_count=5,
|
| 131 |
)
|
| 132 |
-
|
| 133 |
with gr.Accordion(
|
| 134 |
f"⏳ Pending Evaluation Queue ({len(pending_eval_queue_df)})",
|
| 135 |
open=False,
|
|
@@ -141,52 +130,53 @@ with demo:
|
|
| 141 |
datatype=EVAL_TYPES,
|
| 142 |
row_count=5,
|
| 143 |
)
|
| 144 |
-
with gr.Row():
|
| 145 |
-
gr.Markdown("# ✉️✨ Submit your model here!", elem_classes="markdown-text")
|
| 146 |
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
model_name_textbox = gr.Textbox(label="Model name")
|
| 150 |
-
revision_name_textbox = gr.Textbox(label="Revision commit", placeholder="main")
|
| 151 |
-
model_type = gr.Dropdown(
|
| 152 |
-
choices=[t.to_str(" : ") for t in ModelType if t != ModelType.Unknown],
|
| 153 |
-
label="Model type",
|
| 154 |
-
multiselect=False,
|
| 155 |
-
value=None,
|
| 156 |
-
interactive=True,
|
| 157 |
-
)
|
| 158 |
|
| 159 |
-
with gr.
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
label="
|
| 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 |
with gr.Row():
|
| 192 |
with gr.Accordion("📙 Citation", open=False):
|
|
@@ -201,4 +191,5 @@ with demo:
|
|
| 201 |
scheduler = BackgroundScheduler()
|
| 202 |
scheduler.add_job(restart_space, "interval", seconds=1800)
|
| 203 |
scheduler.start()
|
| 204 |
-
|
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
from apscheduler.schedulers.background import BackgroundScheduler
|
| 4 |
+
from huggingface_hub import snapshot_download
|
| 5 |
|
| 6 |
from src.about import (
|
| 7 |
CITATION_BUTTON_LABEL,
|
|
|
|
| 25 |
)
|
| 26 |
from src.envs import API, EVAL_REQUESTS_PATH, EVAL_RESULTS_PATH, QUEUE_REPO, REPO_ID, RESULTS_REPO, TOKEN
|
| 27 |
from src.populate import get_evaluation_queue_df, get_leaderboard_df
|
| 28 |
+
from src.submission.submit import add_new_eval
|
|
|
|
| 29 |
|
| 30 |
def restart_space():
|
| 31 |
API.restart_space(repo_id=REPO_ID)
|
|
|
|
| 34 |
try:
|
| 35 |
print(EVAL_REQUESTS_PATH)
|
| 36 |
snapshot_download(
|
| 37 |
+
repo_id=QUEUE_REPO,
|
| 38 |
+
local_dir=EVAL_REQUESTS_PATH,
|
| 39 |
+
repo_type="dataset",
|
| 40 |
+
tqdm_class=None,
|
| 41 |
+
etag_timeout=30,
|
| 42 |
+
token=TOKEN
|
| 43 |
)
|
| 44 |
except Exception:
|
| 45 |
restart_space()
|
| 46 |
+
|
| 47 |
try:
|
| 48 |
print(EVAL_RESULTS_PATH)
|
| 49 |
snapshot_download(
|
| 50 |
+
repo_id=RESULTS_REPO,
|
| 51 |
+
local_dir=EVAL_RESULTS_PATH,
|
| 52 |
+
repo_type="dataset",
|
| 53 |
+
tqdm_class=None,
|
| 54 |
+
etag_timeout=30,
|
| 55 |
+
token=TOKEN
|
| 56 |
)
|
| 57 |
except Exception:
|
| 58 |
restart_space()
|
| 59 |
|
|
|
|
| 60 |
LEADERBOARD_DF = get_leaderboard_df(EVAL_RESULTS_PATH, EVAL_REQUESTS_PATH, COLS, BENCHMARK_COLS)
|
| 61 |
|
| 62 |
(
|
|
|
|
| 65 |
pending_eval_queue_df,
|
| 66 |
) = get_evaluation_queue_df(EVAL_REQUESTS_PATH, EVAL_COLS)
|
| 67 |
|
| 68 |
+
# Replaced the problematic Leaderboard component with native Gradio Dataframe
|
| 69 |
def init_leaderboard(dataframe):
|
| 70 |
if dataframe is None or dataframe.empty:
|
| 71 |
+
return gr.Markdown("### No data available in leaderboard.")
|
| 72 |
+
|
| 73 |
+
# We use a standard Dataframe which is much more stable with websockets 15.0+
|
| 74 |
+
return gr.Dataframe(
|
| 75 |
value=dataframe,
|
| 76 |
+
headers=[c.name for c in fields(AutoEvalColumn) if not c.hidden],
|
| 77 |
+
datatype=[c.type for c in fields(AutoEvalColumn) if not c.hidden],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
interactive=False,
|
| 79 |
)
|
| 80 |
|
|
|
|
| 81 |
demo = gr.Blocks(css=custom_css)
|
| 82 |
+
|
| 83 |
with demo:
|
| 84 |
gr.HTML(TITLE)
|
| 85 |
gr.Markdown(INTRODUCTION_TEXT, elem_classes="markdown-text")
|
|
|
|
| 119 |
datatype=EVAL_TYPES,
|
| 120 |
row_count=5,
|
| 121 |
)
|
|
|
|
| 122 |
with gr.Accordion(
|
| 123 |
f"⏳ Pending Evaluation Queue ({len(pending_eval_queue_df)})",
|
| 124 |
open=False,
|
|
|
|
| 130 |
datatype=EVAL_TYPES,
|
| 131 |
row_count=5,
|
| 132 |
)
|
|
|
|
|
|
|
| 133 |
|
| 134 |
+
with gr.Row():
|
| 135 |
+
gr.Markdown("# ✉️✨ Submit your model here!", elem_classes="markdown-text")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
|
| 137 |
+
with gr.Row():
|
| 138 |
+
with gr.Column():
|
| 139 |
+
model_name_textbox = gr.Textbox(label="Model name")
|
| 140 |
+
revision_name_textbox = gr.Textbox(label="Revision commit", placeholder="main")
|
| 141 |
+
model_type = gr.Dropdown(
|
| 142 |
+
choices=[t.to_str(" : ") for t in ModelType if t != ModelType.Unknown],
|
| 143 |
+
label="Model type",
|
| 144 |
+
multiselect=False,
|
| 145 |
+
value=None,
|
| 146 |
+
interactive=True,
|
| 147 |
+
)
|
| 148 |
+
|
| 149 |
+
with gr.Column():
|
| 150 |
+
precision = gr.Dropdown(
|
| 151 |
+
choices=[i.value.name for i in Precision if i != Precision.Unknown],
|
| 152 |
+
label="Precision",
|
| 153 |
+
multiselect=False,
|
| 154 |
+
value="float16",
|
| 155 |
+
interactive=True,
|
| 156 |
+
)
|
| 157 |
+
weight_type = gr.Dropdown(
|
| 158 |
+
choices=[i.value.name for i in WeightType],
|
| 159 |
+
label="Weights type",
|
| 160 |
+
multiselect=False,
|
| 161 |
+
value="Original",
|
| 162 |
+
interactive=True,
|
| 163 |
+
)
|
| 164 |
+
base_model_name_textbox = gr.Textbox(label="Base model (for delta or adapter weights)")
|
| 165 |
+
|
| 166 |
+
submit_button = gr.Button("Submit Eval")
|
| 167 |
+
submission_result = gr.Markdown()
|
| 168 |
+
submit_button.click(
|
| 169 |
+
add_new_eval,
|
| 170 |
+
[
|
| 171 |
+
model_name_textbox,
|
| 172 |
+
base_model_name_textbox,
|
| 173 |
+
revision_name_textbox,
|
| 174 |
+
precision,
|
| 175 |
+
weight_type,
|
| 176 |
+
model_type,
|
| 177 |
+
],
|
| 178 |
+
submission_result,
|
| 179 |
+
)
|
| 180 |
|
| 181 |
with gr.Row():
|
| 182 |
with gr.Accordion("📙 Citation", open=False):
|
|
|
|
| 191 |
scheduler = BackgroundScheduler()
|
| 192 |
scheduler.add_job(restart_space, "interval", seconds=1800)
|
| 193 |
scheduler.start()
|
| 194 |
+
|
| 195 |
+
demo.queue(default_concurrency_limit=40).launch()
|