Spaces:
Running
on
Zero
Running
on
Zero
Commit
β’
6fae90e
1
Parent(s):
8782f16
add config and split dropdown
Browse files
app.py
CHANGED
@@ -19,7 +19,7 @@ from transformers import AutoModel, AutoTokenizer, AutoConfig
|
|
19 |
from tqdm import tqdm
|
20 |
|
21 |
|
22 |
-
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
|
23 |
|
24 |
|
25 |
session = requests.Session()
|
@@ -74,7 +74,7 @@ def plot_and_df(texts, preds):
|
|
74 |
)
|
75 |
# counts.reset_index(inplace=True)
|
76 |
return (
|
77 |
-
gr.BarPlot(counts_df, x="quality", y="count"),
|
78 |
texts_df[texts_df["quality"] == "Low"][["text"]][:20],
|
79 |
texts_df[texts_df["quality"] == "Medium"][["text"]][:20],
|
80 |
texts_df[texts_df["quality"] == "High"][["text"]][:20],
|
@@ -82,14 +82,14 @@ def plot_and_df(texts, preds):
|
|
82 |
|
83 |
|
84 |
@spaces.GPU
|
85 |
-
def run_quality_check(dataset, column, batch_size, num_examples):
|
86 |
-
info_resp = session.get(f"https://datasets-server.huggingface.co/info?dataset={dataset}", timeout=3).json()
|
87 |
-
if "error" in info_resp:
|
88 |
-
|
89 |
-
|
90 |
-
config = "default" if "default" in info_resp["dataset_info"] else next(iter(info_resp["dataset_info"]))
|
91 |
-
split = "train" if "train" in info_resp["dataset_info"][config]["splits"] else next(
|
92 |
-
|
93 |
logging.info(f"Fetching data for {dataset} {config} {split}")
|
94 |
try:
|
95 |
data = pl.read_parquet(f"hf://datasets/{dataset}@~parquet/{config}/{split}/0000.parquet", columns=[column])
|
@@ -238,30 +238,68 @@ with gr.Blocks() as demo:
|
|
238 |
## Select dataset and text column
|
239 |
"""
|
240 |
)
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
|
|
|
|
|
|
|
|
|
|
247 |
# config_name = "default" # TODO: user input
|
248 |
with gr.Accordion("Dataset preview", open=False):
|
249 |
-
@gr.render(inputs=dataset_name)
|
250 |
-
def embed(name):
|
251 |
html_code = f"""
|
252 |
<iframe
|
253 |
-
src="https://huggingface.co/datasets/{name}/embed/viewer/
|
254 |
frameborder="0"
|
255 |
width="100%"
|
256 |
-
height="
|
257 |
></iframe>
|
258 |
"""
|
259 |
return gr.HTML(value=html_code)
|
260 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
261 |
text_column = gr.Textbox(placeholder="text", label="Text colum name to check (data must be non-nested, raw texts!)")
|
262 |
|
263 |
gr.Markdown("## Run nvidia quality classifier")
|
264 |
-
batch_size = gr.Slider(0,
|
265 |
num_examples = gr.Number(500, label="Number of first examples to check")
|
266 |
gr_check_btn = gr.Button("Check Dataset")
|
267 |
progress_bar = gr.Label(show_label=False)
|
@@ -279,7 +317,7 @@ with gr.Blocks() as demo:
|
|
279 |
texts_df = gr.DataFrame(visible=False)
|
280 |
gr_check_btn.click(
|
281 |
run_quality_check,
|
282 |
-
inputs=[dataset_name, text_column, batch_size, num_examples],
|
283 |
outputs=[progress_bar, plot, df_low, df_medium, df_high, texts_df]
|
284 |
)
|
285 |
|
|
|
19 |
from tqdm import tqdm
|
20 |
|
21 |
|
22 |
+
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")
|
23 |
|
24 |
|
25 |
session = requests.Session()
|
|
|
74 |
)
|
75 |
# counts.reset_index(inplace=True)
|
76 |
return (
|
77 |
+
gr.BarPlot(counts_df, x="quality", y="count", sort=None),
|
78 |
texts_df[texts_df["quality"] == "Low"][["text"]][:20],
|
79 |
texts_df[texts_df["quality"] == "Medium"][["text"]][:20],
|
80 |
texts_df[texts_df["quality"] == "High"][["text"]][:20],
|
|
|
82 |
|
83 |
|
84 |
@spaces.GPU
|
85 |
+
def run_quality_check(dataset, config, split, column, batch_size, num_examples):
|
86 |
+
# info_resp = session.get(f"https://datasets-server.huggingface.co/info?dataset={dataset}", timeout=3).json()
|
87 |
+
# if "error" in info_resp:
|
88 |
+
# yield "β " + info_resp["error"], gr.BarPlot(), pd.DataFrame(), pd.DataFrame(), pd.DataFrame(), pd.DataFrame(),
|
89 |
+
# return
|
90 |
+
# config = "default" if "default" in info_resp["dataset_info"] else next(iter(info_resp["dataset_info"]))
|
91 |
+
# split = "train" if "train" in info_resp["dataset_info"][config]["splits"] else next(
|
92 |
+
# iter(info_resp["dataset_info"][config]["splits"]))
|
93 |
logging.info(f"Fetching data for {dataset} {config} {split}")
|
94 |
try:
|
95 |
data = pl.read_parquet(f"hf://datasets/{dataset}@~parquet/{config}/{split}/0000.parquet", columns=[column])
|
|
|
238 |
## Select dataset and text column
|
239 |
"""
|
240 |
)
|
241 |
+
with gr.Row():
|
242 |
+
with gr.Column(scale=3):
|
243 |
+
dataset_name = HuggingfaceHubSearch(
|
244 |
+
label="Hub Dataset ID",
|
245 |
+
placeholder="Search for dataset id on Huggingface",
|
246 |
+
search_type="dataset",
|
247 |
+
# value="fka/awesome-chatgpt-prompts",
|
248 |
+
)
|
249 |
+
subset_dropdown = gr.Dropdown(info="Subset", show_label=False, visible=False)
|
250 |
+
split_dropdown = gr.Dropdown(info="Split", show_label=False, visible=False)
|
251 |
+
|
252 |
# config_name = "default" # TODO: user input
|
253 |
with gr.Accordion("Dataset preview", open=False):
|
254 |
+
@gr.render(inputs=[dataset_name, subset_dropdown, split_dropdown])
|
255 |
+
def embed(name, subset, split):
|
256 |
html_code = f"""
|
257 |
<iframe
|
258 |
+
src="https://huggingface.co/datasets/{name}/embed/viewer/{subset}/{split}"
|
259 |
frameborder="0"
|
260 |
width="100%"
|
261 |
+
height="600px"
|
262 |
></iframe>
|
263 |
"""
|
264 |
return gr.HTML(value=html_code)
|
265 |
|
266 |
+
def _resolve_dataset_selection(dataset: str, default_subset: str, default_split: str):
|
267 |
+
if "/" not in dataset.strip().strip("/"):
|
268 |
+
return {
|
269 |
+
subset_dropdown: gr.Dropdown(visible=False),
|
270 |
+
split_dropdown: gr.Dropdown(visible=False),
|
271 |
+
}
|
272 |
+
info_resp = session.get(f"https://datasets-server.huggingface.co/info?dataset={dataset}", timeout=3).json()
|
273 |
+
if "error" in info_resp:
|
274 |
+
return {
|
275 |
+
subset_dropdown: gr.Dropdown(visible=False),
|
276 |
+
split_dropdown: gr.Dropdown(visible=False),
|
277 |
+
}
|
278 |
+
subsets: list[str] = list(info_resp["dataset_info"])
|
279 |
+
subset = default_subset if default_subset in subsets else subsets[0]
|
280 |
+
splits: list[str] = info_resp["dataset_info"][subset]["splits"]
|
281 |
+
split = default_split if default_split in splits else splits[0]
|
282 |
+
return {
|
283 |
+
subset_dropdown: gr.Dropdown(value=subset, choices=subsets, visible=len(subsets) > 1),
|
284 |
+
split_dropdown: gr.Dropdown(value=split, choices=splits, visible=len(splits) > 1),
|
285 |
+
}
|
286 |
+
|
287 |
+
@dataset_name.change(inputs=[dataset_name], outputs=[subset_dropdown, split_dropdown])
|
288 |
+
def show_input_from_subset_dropdown(dataset: str) -> dict:
|
289 |
+
return _resolve_dataset_selection(dataset, default_subset="default", default_split="train")
|
290 |
+
|
291 |
+
@subset_dropdown.change(inputs=[dataset_name, subset_dropdown], outputs=[subset_dropdown, split_dropdown])
|
292 |
+
def show_input_from_subset_dropdown(dataset: str, subset: str) -> dict:
|
293 |
+
return _resolve_dataset_selection(dataset, default_subset=subset, default_split="train")
|
294 |
+
|
295 |
+
@split_dropdown.change(inputs=[dataset_name, subset_dropdown, split_dropdown], outputs=[subset_dropdown, split_dropdown])
|
296 |
+
def show_input_from_split_dropdown(dataset: str, subset: str, split: str) -> dict:
|
297 |
+
return _resolve_dataset_selection(dataset, default_subset=subset, default_split=split)
|
298 |
+
|
299 |
text_column = gr.Textbox(placeholder="text", label="Text colum name to check (data must be non-nested, raw texts!)")
|
300 |
|
301 |
gr.Markdown("## Run nvidia quality classifier")
|
302 |
+
batch_size = gr.Slider(0, 64, 32, step=4, label="Inference batch size (set this to smaller value if this space crashes.)")
|
303 |
num_examples = gr.Number(500, label="Number of first examples to check")
|
304 |
gr_check_btn = gr.Button("Check Dataset")
|
305 |
progress_bar = gr.Label(show_label=False)
|
|
|
317 |
texts_df = gr.DataFrame(visible=False)
|
318 |
gr_check_btn.click(
|
319 |
run_quality_check,
|
320 |
+
inputs=[dataset_name, subset_dropdown, split_dropdown, text_column, batch_size, num_examples],
|
321 |
outputs=[progress_bar, plot, df_low, df_medium, df_high, texts_df]
|
322 |
)
|
323 |
|