Spaces:
Running
Running
ZeroCommand
commited on
Commit
•
7055d8b
1
Parent(s):
666860b
GSK-2844-to-2841-fix-for-model-url-add-doc-and-UI (#120)
Browse files- add doc seo; fix model id link; fix leaderboard; add loading bar (c88b4981105a1857d96638bb7ccc7f7c99d80ad4)
- app_leaderboard.py +1 -1
- app_text_classification.py +13 -7
- text_classification.py +2 -19
- text_classification_ui_helpers.py +39 -11
- wordings.py +2 -1
app_leaderboard.py
CHANGED
@@ -90,7 +90,7 @@ def get_demo(leaderboard_tab):
|
|
90 |
column_names = records.columns.tolist()
|
91 |
issue_columns = column_names[:11]
|
92 |
info_columns = column_names[15:]
|
93 |
-
default_columns = ["dataset_id", "total_issues", "report_link"]
|
94 |
default_df = records[default_columns] # extract columns selected
|
95 |
types = get_types(default_df)
|
96 |
display_df = get_display_df(default_df) # the styled dataframe to display
|
|
|
90 |
column_names = records.columns.tolist()
|
91 |
issue_columns = column_names[:11]
|
92 |
info_columns = column_names[15:]
|
93 |
+
default_columns = ["model_id", "dataset_id", "total_issues", "report_link"]
|
94 |
default_df = records[default_columns] # extract columns selected
|
95 |
types = get_types(default_df)
|
96 |
display_df = get_display_df(default_df) # the styled dataframe to display
|
app_text_classification.py
CHANGED
@@ -59,7 +59,7 @@ def get_demo():
|
|
59 |
with gr.Row():
|
60 |
first_line_ds = gr.DataFrame(label="Dataset Preview", visible=False)
|
61 |
with gr.Row():
|
62 |
-
|
63 |
with gr.Row():
|
64 |
example_btn = gr.Button(
|
65 |
"Validate Model & Dataset",
|
@@ -67,9 +67,10 @@ def get_demo():
|
|
67 |
variant="primary",
|
68 |
interactive=False,
|
69 |
)
|
70 |
-
|
71 |
with gr.Row():
|
72 |
-
|
|
|
|
|
73 |
with gr.Row():
|
74 |
example_prediction = gr.Label(label="Model Sample Prediction", visible=False)
|
75 |
|
@@ -153,7 +154,7 @@ def get_demo():
|
|
153 |
triggers=[dataset_id_input.input, dataset_id_input.select],
|
154 |
fn=check_dataset,
|
155 |
inputs=[dataset_id_input],
|
156 |
-
outputs=[dataset_config_input, dataset_split_input,
|
157 |
)
|
158 |
|
159 |
dataset_config_input.change(fn=get_dataset_splits, inputs=[dataset_id_input, dataset_config_input], outputs=[dataset_split_input])
|
@@ -197,7 +198,12 @@ def get_demo():
|
|
197 |
dataset_config_input,
|
198 |
dataset_split_input,
|
199 |
],
|
200 |
-
outputs=[
|
|
|
|
|
|
|
|
|
|
|
201 |
)
|
202 |
|
203 |
gr.on(
|
@@ -215,11 +221,11 @@ def get_demo():
|
|
215 |
inference_token,
|
216 |
],
|
217 |
outputs=[
|
218 |
-
|
219 |
example_prediction,
|
220 |
column_mapping_accordion,
|
221 |
run_btn,
|
222 |
-
|
223 |
*column_mappings,
|
224 |
],
|
225 |
)
|
|
|
59 |
with gr.Row():
|
60 |
first_line_ds = gr.DataFrame(label="Dataset Preview", visible=False)
|
61 |
with gr.Row():
|
62 |
+
loading_dataset_info = gr.HTML(visible=True)
|
63 |
with gr.Row():
|
64 |
example_btn = gr.Button(
|
65 |
"Validate Model & Dataset",
|
|
|
67 |
variant="primary",
|
68 |
interactive=False,
|
69 |
)
|
|
|
70 |
with gr.Row():
|
71 |
+
loading_validation = gr.HTML(visible=True)
|
72 |
+
with gr.Row():
|
73 |
+
validation_result = gr.HTML(visible=False)
|
74 |
with gr.Row():
|
75 |
example_prediction = gr.Label(label="Model Sample Prediction", visible=False)
|
76 |
|
|
|
154 |
triggers=[dataset_id_input.input, dataset_id_input.select],
|
155 |
fn=check_dataset,
|
156 |
inputs=[dataset_id_input],
|
157 |
+
outputs=[dataset_config_input, dataset_split_input, loading_dataset_info]
|
158 |
)
|
159 |
|
160 |
dataset_config_input.change(fn=get_dataset_splits, inputs=[dataset_id_input, dataset_config_input], outputs=[dataset_split_input])
|
|
|
198 |
dataset_config_input,
|
199 |
dataset_split_input,
|
200 |
],
|
201 |
+
outputs=[
|
202 |
+
example_btn,
|
203 |
+
first_line_ds,
|
204 |
+
validation_result,
|
205 |
+
example_prediction,
|
206 |
+
column_mapping_accordion,],
|
207 |
)
|
208 |
|
209 |
gr.on(
|
|
|
221 |
inference_token,
|
222 |
],
|
223 |
outputs=[
|
224 |
+
validation_result,
|
225 |
example_prediction,
|
226 |
column_mapping_accordion,
|
227 |
run_btn,
|
228 |
+
loading_validation,
|
229 |
*column_mappings,
|
230 |
],
|
231 |
)
|
text_classification.py
CHANGED
@@ -380,7 +380,7 @@ def text_classification_fix_column_mapping(column_mapping, ppl, d_id, config, sp
|
|
380 |
|
381 |
def strip_model_id_from_url(model_id):
|
382 |
if model_id.startswith("https://huggingface.co/"):
|
383 |
-
return "/".join(model_id.split("/")[-2])
|
384 |
return model_id
|
385 |
|
386 |
def check_hf_token_validity(hf_token):
|
@@ -393,21 +393,4 @@ def check_hf_token_validity(hf_token):
|
|
393 |
response = requests.get(AUTH_CHECK_URL, headers=headers)
|
394 |
if response.status_code != 200:
|
395 |
return False
|
396 |
-
return True
|
397 |
-
|
398 |
-
def get_dataset_info_from_server(dataset_id):
|
399 |
-
url = "https://datasets-server.huggingface.co/splits?dataset=" + dataset_id
|
400 |
-
response = requests.get(url)
|
401 |
-
if response.status_code != 200:
|
402 |
-
return None
|
403 |
-
return response.json()
|
404 |
-
|
405 |
-
def get_dataset_splits(dataset_id, dataset_config):
|
406 |
-
dataset_info = get_dataset_info_from_server(dataset_id)
|
407 |
-
if dataset_info is None:
|
408 |
-
return None
|
409 |
-
try:
|
410 |
-
splits = dataset_info["splits"]
|
411 |
-
return [split["split"] for split in splits if split["config"] == dataset_config]
|
412 |
-
except Exception:
|
413 |
-
return None
|
|
|
380 |
|
381 |
def strip_model_id_from_url(model_id):
|
382 |
if model_id.startswith("https://huggingface.co/"):
|
383 |
+
return "/".join(model_id.split("/")[-2:])
|
384 |
return model_id
|
385 |
|
386 |
def check_hf_token_validity(hf_token):
|
|
|
393 |
response = requests.get(AUTH_CHECK_URL, headers=headers)
|
394 |
if response.status_code != 200:
|
395 |
return False
|
396 |
+
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
text_classification_ui_helpers.py
CHANGED
@@ -179,29 +179,57 @@ def precheck_model_ds_enable_example_btn(
|
|
179 |
model_task = check_model_task(model_id)
|
180 |
preload_hf_inference_api(model_id)
|
181 |
|
182 |
-
if model_task is None or model_task != "text-classification":
|
183 |
-
gr.Warning(NOT_TEXT_CLASSIFICATION_MODEL_RAW)
|
184 |
-
return (gr.update(interactive=False), gr.update(visible=False),"")
|
185 |
-
|
186 |
if dataset_config is None or dataset_split is None or len(dataset_config) == 0:
|
187 |
-
return (
|
188 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
189 |
try:
|
190 |
ds = datasets.load_dataset(dataset_id, dataset_config, trust_remote_code=True)
|
191 |
df: pd.DataFrame = ds[dataset_split].to_pandas().head(5)
|
192 |
ds_labels, ds_features = get_labels_and_features_from_dataset(ds[dataset_split])
|
193 |
-
|
194 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
195 |
|
196 |
if not isinstance(ds_labels, list) or not isinstance(ds_features, list):
|
197 |
gr.Warning(CHECK_CONFIG_OR_SPLIT_RAW)
|
198 |
-
return (
|
|
|
|
|
|
|
|
|
|
|
|
|
199 |
|
200 |
-
return (
|
|
|
|
|
|
|
|
|
|
|
|
|
201 |
except Exception as e:
|
202 |
# Config or split wrong
|
203 |
logger.warn(f"Check your dataset {dataset_id} and config {dataset_config} on split {dataset_split}: {e}")
|
204 |
-
return (
|
|
|
|
|
|
|
|
|
|
|
|
|
205 |
|
206 |
|
207 |
def align_columns_and_show_prediction(
|
|
|
179 |
model_task = check_model_task(model_id)
|
180 |
preload_hf_inference_api(model_id)
|
181 |
|
|
|
|
|
|
|
|
|
182 |
if dataset_config is None or dataset_split is None or len(dataset_config) == 0:
|
183 |
+
return (
|
184 |
+
gr.update(interactive=False),
|
185 |
+
gr.update(visible=False),
|
186 |
+
gr.update(visible=False),
|
187 |
+
gr.update(visible=False),
|
188 |
+
gr.update(visible=False),
|
189 |
+
)
|
190 |
+
|
191 |
try:
|
192 |
ds = datasets.load_dataset(dataset_id, dataset_config, trust_remote_code=True)
|
193 |
df: pd.DataFrame = ds[dataset_split].to_pandas().head(5)
|
194 |
ds_labels, ds_features = get_labels_and_features_from_dataset(ds[dataset_split])
|
195 |
+
|
196 |
+
if model_task is None or model_task != "text-classification":
|
197 |
+
gr.Warning(NOT_TEXT_CLASSIFICATION_MODEL_RAW)
|
198 |
+
return (
|
199 |
+
gr.update(interactive=False),
|
200 |
+
gr.update(value=df, visible=True),
|
201 |
+
gr.update(visible=False),
|
202 |
+
gr.update(visible=False),
|
203 |
+
gr.update(visible=False),
|
204 |
+
)
|
205 |
|
206 |
if not isinstance(ds_labels, list) or not isinstance(ds_features, list):
|
207 |
gr.Warning(CHECK_CONFIG_OR_SPLIT_RAW)
|
208 |
+
return (
|
209 |
+
gr.update(interactive=False),
|
210 |
+
gr.update(value=df, visible=True),
|
211 |
+
gr.update(visible=False),
|
212 |
+
gr.update(visible=False),
|
213 |
+
gr.update(visible=False),
|
214 |
+
)
|
215 |
|
216 |
+
return (
|
217 |
+
gr.update(interactive=True),
|
218 |
+
gr.update(value=df, visible=True),
|
219 |
+
gr.update(visible=False),
|
220 |
+
gr.update(visible=False),
|
221 |
+
gr.update(visible=False),
|
222 |
+
)
|
223 |
except Exception as e:
|
224 |
# Config or split wrong
|
225 |
logger.warn(f"Check your dataset {dataset_id} and config {dataset_config} on split {dataset_split}: {e}")
|
226 |
+
return (
|
227 |
+
gr.update(interactive=False),
|
228 |
+
gr.update(visible=False),
|
229 |
+
gr.update(visible=False),
|
230 |
+
gr.update(visible=False),
|
231 |
+
gr.update(visible=False),
|
232 |
+
)
|
233 |
|
234 |
|
235 |
def align_columns_and_show_prediction(
|
wordings.py
CHANGED
@@ -2,7 +2,8 @@ INTRODUCTION_MD = """
|
|
2 |
<h1 style="text-align: center;">
|
3 |
🐢Giskard Evaluator - Text Classification
|
4 |
</h1>
|
5 |
-
Welcome to the Giskard Evaluator Space! Get a model vulnerability report immediately by simply sharing your model and dataset id below.
|
|
|
6 |
"""
|
7 |
CONFIRM_MAPPING_DETAILS_MD = """
|
8 |
<h1 style="text-align: center;">
|
|
|
2 |
<h1 style="text-align: center;">
|
3 |
🐢Giskard Evaluator - Text Classification
|
4 |
</h1>
|
5 |
+
Welcome to the Giskard Evaluator Space! Get a model vulnerability report immediately by simply sharing your model and dataset id below.
|
6 |
+
You can also checkout our library documentation <a href="https://docs.giskard.ai/en/latest/getting_started/quickstart/index.html">here</a>.
|
7 |
"""
|
8 |
CONFIRM_MAPPING_DETAILS_MD = """
|
9 |
<h1 style="text-align: center;">
|