Spaces:
Sleeping
Sleeping
Commit
•
8c47a22
1
Parent(s):
125b0cb
GSK-2498-suggest-a-dataset-for-model (#46)
Browse files- add suggested dataset (4045dfcc95c3cbf74929a1b7a51344b0e90f843b)
- clean up recommend dataset (a2a18b34c7a50f9f6d650ea24ada9df0d59c418a)
- change textbox to dropdown (983e75b10c93736c653e7b00b4589fe9f5723648)
- change run in this space wording (08c711a057e169b1dc5323ceff015ecf62eaaeca)
- make inference api default; improve event triggers (1dcb2d8e955c645ad99909b73add2d86aed094a1)
- show all options when no model id matched (6de1a1d3ea97fdf5cad2de401f7ca87de9fa06e3)
- fix dropdown choices pd list (107357d497b65c8885ce27918e0fe8bf13e7ce72)
Co-authored-by: zcy <ZeroCommand@users.noreply.huggingface.co>
- app_leaderboard.py +4 -1
- app_text_classification.py +43 -12
- leaderboard.py +3 -0
- text_classification_ui_helpers.py +13 -3
app_leaderboard.py
CHANGED
@@ -7,6 +7,7 @@ from fetch_utils import (check_dataset_and_get_config,
|
|
7 |
check_dataset_and_get_split)
|
8 |
from text_classification_ui_helpers import LEADERBOARD
|
9 |
|
|
|
10 |
|
11 |
def get_records_from_dataset_repo(dataset_id):
|
12 |
dataset_config = check_dataset_and_get_config(dataset_id)
|
@@ -74,7 +75,8 @@ def get_display_df(df):
|
|
74 |
|
75 |
|
76 |
def get_demo():
|
77 |
-
records = get_records_from_dataset_repo(LEADERBOARD)
|
|
|
78 |
|
79 |
model_ids = get_model_ids(records)
|
80 |
dataset_ids = get_dataset_ids(records)
|
@@ -124,6 +126,7 @@ def get_demo():
|
|
124 |
outputs=[leaderboard_df],
|
125 |
)
|
126 |
def filter_table(model_id, dataset_id, columns, task):
|
|
|
127 |
# filter the table based on task
|
128 |
df = records[(records["task"] == task)]
|
129 |
# filter the table based on the model_id and dataset_id
|
|
|
7 |
check_dataset_and_get_split)
|
8 |
from text_classification_ui_helpers import LEADERBOARD
|
9 |
|
10 |
+
import leaderboard
|
11 |
|
12 |
def get_records_from_dataset_repo(dataset_id):
|
13 |
dataset_config = check_dataset_and_get_config(dataset_id)
|
|
|
75 |
|
76 |
|
77 |
def get_demo():
|
78 |
+
leaderboard.records = get_records_from_dataset_repo(LEADERBOARD)
|
79 |
+
records = leaderboard.records
|
80 |
|
81 |
model_ids = get_model_ids(records)
|
82 |
dataset_ids = get_dataset_ids(records)
|
|
|
126 |
outputs=[leaderboard_df],
|
127 |
)
|
128 |
def filter_table(model_id, dataset_id, columns, task):
|
129 |
+
records = leaderboard.records
|
130 |
# filter the table based on task
|
131 |
df = records[(records["task"] == task)]
|
132 |
# filter the table based on the model_id and dataset_id
|
app_text_classification.py
CHANGED
@@ -4,6 +4,7 @@ import gradio as gr
|
|
4 |
|
5 |
from io_utils import get_logs_file, read_scanners, write_scanners
|
6 |
from text_classification_ui_helpers import (
|
|
|
7 |
align_columns_and_show_prediction,
|
8 |
check_dataset,
|
9 |
deselect_run_inference,
|
@@ -18,7 +19,6 @@ MAX_LABELS = 40
|
|
18 |
MAX_FEATURES = 20
|
19 |
|
20 |
EXAMPLE_MODEL_ID = "cardiffnlp/twitter-roberta-base-sentiment-latest"
|
21 |
-
EXAMPLE_DATA_ID = "tweet_eval"
|
22 |
CONFIG_PATH = "./config.yaml"
|
23 |
|
24 |
|
@@ -34,10 +34,13 @@ def get_demo():
|
|
34 |
placeholder=EXAMPLE_MODEL_ID + " (press enter to confirm)",
|
35 |
)
|
36 |
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
41 |
|
42 |
with gr.Row():
|
43 |
dataset_config_input = gr.Dropdown(label="Dataset Config", visible=False, allow_custom_value=True)
|
@@ -77,15 +80,16 @@ def get_demo():
|
|
77 |
for _ in range(MAX_LABELS, MAX_LABELS + MAX_FEATURES):
|
78 |
column_mappings.append(gr.Dropdown(visible=False))
|
79 |
|
80 |
-
with gr.Accordion(label="Model Wrap Advance Config
|
81 |
-
|
82 |
-
run_inference = gr.Checkbox(value=False, label="Run with Inference API")
|
83 |
inference_token = gr.Textbox(
|
84 |
value="",
|
85 |
label="HF Token for Inference API",
|
86 |
-
visible=
|
87 |
interactive=True,
|
88 |
)
|
|
|
|
|
89 |
|
90 |
with gr.Accordion(label="Scanner Advance Config (optional)", open=False):
|
91 |
scanners = gr.CheckboxGroup(label="Scan Settings", visible=True)
|
@@ -149,6 +153,13 @@ def get_demo():
|
|
149 |
outputs=[inference_token, run_inference],
|
150 |
)
|
151 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
152 |
gr.on(
|
153 |
triggers=[label.change for label in column_mappings],
|
154 |
fn=write_column_mapping_to_config,
|
@@ -196,6 +207,8 @@ def get_demo():
|
|
196 |
dataset_config_input,
|
197 |
dataset_split_input,
|
198 |
uid_label,
|
|
|
|
|
199 |
],
|
200 |
outputs=[
|
201 |
example_input,
|
@@ -225,7 +238,11 @@ def get_demo():
|
|
225 |
outputs=[run_btn, logs, uid_label],
|
226 |
)
|
227 |
|
228 |
-
def enable_run_btn():
|
|
|
|
|
|
|
|
|
229 |
return gr.update(interactive=True)
|
230 |
|
231 |
gr.on(
|
@@ -236,13 +253,27 @@ def get_demo():
|
|
236 |
scanners.input,
|
237 |
],
|
238 |
fn=enable_run_btn,
|
239 |
-
inputs=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
240 |
outputs=[run_btn],
|
241 |
)
|
242 |
|
243 |
gr.on(
|
244 |
triggers=[label.input for label in column_mappings],
|
245 |
fn=enable_run_btn,
|
246 |
-
inputs=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
247 |
outputs=[run_btn],
|
248 |
)
|
|
|
4 |
|
5 |
from io_utils import get_logs_file, read_scanners, write_scanners
|
6 |
from text_classification_ui_helpers import (
|
7 |
+
get_related_datasets_from_leaderboard,
|
8 |
align_columns_and_show_prediction,
|
9 |
check_dataset,
|
10 |
deselect_run_inference,
|
|
|
19 |
MAX_FEATURES = 20
|
20 |
|
21 |
EXAMPLE_MODEL_ID = "cardiffnlp/twitter-roberta-base-sentiment-latest"
|
|
|
22 |
CONFIG_PATH = "./config.yaml"
|
23 |
|
24 |
|
|
|
34 |
placeholder=EXAMPLE_MODEL_ID + " (press enter to confirm)",
|
35 |
)
|
36 |
|
37 |
+
with gr.Column():
|
38 |
+
dataset_id_input = gr.Dropdown(
|
39 |
+
choices=[],
|
40 |
+
value="",
|
41 |
+
allow_custom_value=True,
|
42 |
+
label="Hugging Face Dataset id",
|
43 |
+
)
|
44 |
|
45 |
with gr.Row():
|
46 |
dataset_config_input = gr.Dropdown(label="Dataset Config", visible=False, allow_custom_value=True)
|
|
|
80 |
for _ in range(MAX_LABELS, MAX_LABELS + MAX_FEATURES):
|
81 |
column_mappings.append(gr.Dropdown(visible=False))
|
82 |
|
83 |
+
with gr.Accordion(label="Model Wrap Advance Config", open=True):
|
84 |
+
run_inference = gr.Checkbox(value=True, label="Run with Inference API")
|
|
|
85 |
inference_token = gr.Textbox(
|
86 |
value="",
|
87 |
label="HF Token for Inference API",
|
88 |
+
visible=True,
|
89 |
interactive=True,
|
90 |
)
|
91 |
+
run_local = gr.Checkbox(value=False, label="Run Locally with Pipeline [Slow]")
|
92 |
+
|
93 |
|
94 |
with gr.Accordion(label="Scanner Advance Config (optional)", open=False):
|
95 |
scanners = gr.CheckboxGroup(label="Scan Settings", visible=True)
|
|
|
153 |
outputs=[inference_token, run_inference],
|
154 |
)
|
155 |
|
156 |
+
gr.on(
|
157 |
+
triggers=[model_id_input.change],
|
158 |
+
fn=get_related_datasets_from_leaderboard,
|
159 |
+
inputs=[model_id_input],
|
160 |
+
outputs=[dataset_id_input],
|
161 |
+
)
|
162 |
+
|
163 |
gr.on(
|
164 |
triggers=[label.change for label in column_mappings],
|
165 |
fn=write_column_mapping_to_config,
|
|
|
207 |
dataset_config_input,
|
208 |
dataset_split_input,
|
209 |
uid_label,
|
210 |
+
run_inference,
|
211 |
+
inference_token,
|
212 |
],
|
213 |
outputs=[
|
214 |
example_input,
|
|
|
238 |
outputs=[run_btn, logs, uid_label],
|
239 |
)
|
240 |
|
241 |
+
def enable_run_btn(run_inference, inference_token, model_id, dataset_id, dataset_config, dataset_split):
|
242 |
+
if run_inference and inference_token == "":
|
243 |
+
return gr.update(interactive=False)
|
244 |
+
if model_id == "" or dataset_id == "" or dataset_config == "" or dataset_split == "":
|
245 |
+
return gr.update(interactive=False)
|
246 |
return gr.update(interactive=True)
|
247 |
|
248 |
gr.on(
|
|
|
253 |
scanners.input,
|
254 |
],
|
255 |
fn=enable_run_btn,
|
256 |
+
inputs=[
|
257 |
+
run_inference,
|
258 |
+
inference_token,
|
259 |
+
model_id_input,
|
260 |
+
dataset_id_input,
|
261 |
+
dataset_config_input,
|
262 |
+
dataset_split_input
|
263 |
+
],
|
264 |
outputs=[run_btn],
|
265 |
)
|
266 |
|
267 |
gr.on(
|
268 |
triggers=[label.input for label in column_mappings],
|
269 |
fn=enable_run_btn,
|
270 |
+
inputs=[
|
271 |
+
run_inference,
|
272 |
+
inference_token,
|
273 |
+
model_id_input,
|
274 |
+
dataset_id_input,
|
275 |
+
dataset_config_input,
|
276 |
+
dataset_split_input
|
277 |
+
], # FIXME
|
278 |
outputs=[run_btn],
|
279 |
)
|
leaderboard.py
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
|
3 |
+
records = pd.DataFrame()
|
text_classification_ui_helpers.py
CHANGED
@@ -4,6 +4,7 @@ import logging
|
|
4 |
import os
|
5 |
import threading
|
6 |
import uuid
|
|
|
7 |
|
8 |
import datasets
|
9 |
import gradio as gr
|
@@ -42,6 +43,15 @@ HF_GSK_HUB_HF_TOKEN = "GSK_HF_TOKEN"
|
|
42 |
HF_GSK_HUB_UNLOCK_TOKEN = "GSK_HUB_UNLOCK_TOKEN"
|
43 |
|
44 |
LEADERBOARD = "giskard-bot/evaluator-leaderboard"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
|
47 |
logger = logging.getLogger(__file__)
|
@@ -207,7 +217,7 @@ def precheck_model_ds_enable_example_btn(
|
|
207 |
|
208 |
|
209 |
def align_columns_and_show_prediction(
|
210 |
-
model_id, dataset_id, dataset_config, dataset_split, uid
|
211 |
):
|
212 |
ppl = check_model(model_id)
|
213 |
if ppl is None or not isinstance(ppl, TextClassificationPipeline):
|
@@ -268,7 +278,7 @@ def align_columns_and_show_prediction(
|
|
268 |
gr.update(value=MAPPING_STYLED_ERROR_WARNING, visible=True),
|
269 |
gr.update(visible=False),
|
270 |
gr.update(visible=True, open=True),
|
271 |
-
gr.update(interactive=
|
272 |
"",
|
273 |
*column_mappings,
|
274 |
)
|
@@ -280,7 +290,7 @@ def align_columns_and_show_prediction(
|
|
280 |
gr.update(value=get_styled_input(prediction_input), visible=True),
|
281 |
gr.update(value=prediction_output, visible=True),
|
282 |
gr.update(visible=True, open=False),
|
283 |
-
gr.update(interactive=
|
284 |
"",
|
285 |
*column_mappings,
|
286 |
)
|
|
|
4 |
import os
|
5 |
import threading
|
6 |
import uuid
|
7 |
+
import leaderboard
|
8 |
|
9 |
import datasets
|
10 |
import gradio as gr
|
|
|
43 |
HF_GSK_HUB_UNLOCK_TOKEN = "GSK_HUB_UNLOCK_TOKEN"
|
44 |
|
45 |
LEADERBOARD = "giskard-bot/evaluator-leaderboard"
|
46 |
+
def get_related_datasets_from_leaderboard(model_id):
|
47 |
+
records = leaderboard.records
|
48 |
+
model_records = records[records["model_id"] == model_id]
|
49 |
+
datasets_unique = model_records["dataset_id"].unique()
|
50 |
+
if len(datasets_unique) == 0:
|
51 |
+
all_unique_datasets = list(records["dataset_id"].unique())
|
52 |
+
print(type(all_unique_datasets), all_unique_datasets)
|
53 |
+
return gr.update(choices=all_unique_datasets, value="")
|
54 |
+
return gr.update(choices=datasets_unique, value=datasets_unique[0])
|
55 |
|
56 |
|
57 |
logger = logging.getLogger(__file__)
|
|
|
217 |
|
218 |
|
219 |
def align_columns_and_show_prediction(
|
220 |
+
model_id, dataset_id, dataset_config, dataset_split, uid, run_inference, inference_token
|
221 |
):
|
222 |
ppl = check_model(model_id)
|
223 |
if ppl is None or not isinstance(ppl, TextClassificationPipeline):
|
|
|
278 |
gr.update(value=MAPPING_STYLED_ERROR_WARNING, visible=True),
|
279 |
gr.update(visible=False),
|
280 |
gr.update(visible=True, open=True),
|
281 |
+
gr.update(interactive=(run_inference and inference_token != "")),
|
282 |
"",
|
283 |
*column_mappings,
|
284 |
)
|
|
|
290 |
gr.update(value=get_styled_input(prediction_input), visible=True),
|
291 |
gr.update(value=prediction_output, visible=True),
|
292 |
gr.update(visible=True, open=False),
|
293 |
+
gr.update(interactive=(run_inference and inference_token != "")),
|
294 |
"",
|
295 |
*column_mappings,
|
296 |
)
|