Spaces:
Runtime error
Runtime error
Merge pull request #6 from huggingface/add-metadata
Browse files7 unmodified lines89101112131414 unmodified lines29303132333426 unmodified lines616263646566677 unmodified lines757677787980818283848586878889909192939495969798991001011021034 unmodified lines10810911011111211311411511610 unmodified lines1271281291301311321331341357 unmodified lines1431441451461471481491501517 unmodified lines15916016116216316416516616 unmodified lines1831841851861871881891901911921931941951961971984 unmodified lines2032042052062072082092102117 unmodified linesfrom dotenv import load_dotenvfrom huggingface_hub import list_datasetsfrom utils import get_compatible_models, get_metadata, http_get, http_postif Path(".env").is_file():load_dotenv(".env")14 unmodified lines"summarization": 8,}############## APP ##############26 unmodified lineswith st.expander("Advanced configuration"):## Select taskselected_task = st.selectbox("Select a task", list(TASK_TO_ID.keys()))### Select configconfigs = get_dataset_config_names(selected_dataset)selected_config = st.selectbox("Select a config", configs)7 unmodified linesif split["config"] == selected_config:split_names.append(split["split"])selected_split = st.selectbox("Select a split", split_names) # , index=split_names.index(eval_split))## Show columnsrows_resp = http_get(path="/rows",domain="https://datasets-preview.huggingface.tech",params={"dataset": selected_dataset, "config": selected_config, "split": selected_split},).json()col_names = list(pd.json_normalize(rows_resp["rows"][0]["row"]).columns)# splits = metadata[0]["splits"]# split_names = list(splits.values())# eval_split = splits.get("eval_split", split_names[0])# selected_split = st.selectbox("Select a split", split_names, index=split_names.index(eval_split))# TODO: add a function to handle the mapping task <--> column mapping# col_mapping = metadata[0]["col_mapping"]# col_names = list(col_mapping.keys())st.markdown("**Map your data columns**")col1, col2 = st.columns(2)# TODO: find a better way to layout these itemscol_mapping = {}if selected_task in ["binary_classification", "multi_class_classification"]:with col1:4 unmodified linesst.text("")st.markdown("`target` column")with col2:text_col = st.selectbox("This column should contain the text you want to classify", col_names)target_col = st.selectbox("This column should contain the labels you want to assign to the text", col_names)col_mapping[text_col] = "text"col_mapping[target_col] = "target"10 unmodified linestokens_col = st.selectbox("This column should contain the parts of the text (as an array of tokens) you want to assign labels to",col_names,)tags_col = st.selectbox("This column should contain the labels to associate to each part of the text", col_names)col_mapping[tokens_col] = "tokens"col_mapping[tags_col] = "tags"7 unmodified linesst.text("")st.markdown("`target` column")with col2:text_col = st.selectbox("This column should contain the text you want to translate", col_names)target_col = st.selectbox("This column should contain an example translation of the source text", col_names)col_mapping[text_col] = "source"col_mapping[target_col] = "target"7 unmodified linesst.text("")st.markdown("`target` column")with col2:text_col = st.selectbox("This column should contain the text you want to summarize", col_names)target_col = st.selectbox("This column should contain an example summarization of the text", col_names)col_mapping[text_col] = "text"col_mapping[target_col] = "target"16 unmodified linesst.text("")st.markdown("`answers.answer_start` column")with col2:context_col = st.selectbox("This column should contain the question's context", col_names)question_col = st.selectbox("This column should contain the question to be answered, given the context", col_names)answers_text_col = st.selectbox("This column should contain example answers to the question, extracted from the context", col_names)answers_start_col = st.selectbox("This column should contain the indices in the context of the first character of each answers.text",col_names,)col_mapping[context_col] = "context"col_mapping[question_col] = "question"4 unmodified linescompatible_models = get_compatible_models(selected_task, selected_dataset)selected_models = st.multiselect("Select the models you wish to evaluate", compatible_models)submit_button = st.form_submit_button("Make submission")if submit_button:7 unmodified lines8910111213141514 unmodified lines30313233343536373826 unmodified lines65666768697071727374757 unmodified lines83848586878889909192939495969798991001011021031041051061074 unmodified lines11211311411511611711811912012112212312412512610 unmodified lines1371381391401411421431441451461471487 unmodified lines1561571581591601611621631641651661671681691707 unmodified lines17817918018118218318418518618718818919019119219316 unmodified lines2102112122132142152162172182192202212222232242252262272282292302312322332342352362372384 unmodified lines2432442452462472482492507 unmodified linesfrom dotenv import load_dotenvfrom huggingface_hub import list_datasetsfrom utils import (get_compatible_models, get_key, get_metadata, http_get,http_post)if Path(".env").is_file():load_dotenv(".env")14 unmodified lines"summarization": 8,}supported_tasks = list(TASK_TO_ID.keys())############## APP ##############26 unmodified lineswith st.expander("Advanced configuration"):## Select taskselected_task = st.selectbox("Select a task",supported_tasks,index=supported_tasks.index(metadata[0]["task_id"]) if metadata is not None else 0,)### Select configconfigs = get_dataset_config_names(selected_dataset)selected_config = st.selectbox("Select a config", configs)7 unmodified linesif split["config"] == selected_config:split_names.append(split["split"])selected_split = st.selectbox("Select a split",split_names,index=split_names.index(metadata[0]["splits"]["eval_split"]) if metadata is not None else 0,)## Select columnsrows_resp = http_get(path="/rows",domain="https://datasets-preview.huggingface.tech",params={"dataset": selected_dataset, "config": selected_config, "split": selected_split},).json()col_names = list(pd.json_normalize(rows_resp["rows"][0]["row"]).columns)st.markdown("**Map your data columns**")col1, col2 = st.columns(2)# TODO: find a better way to layout these items# TODO: need graceful way of handling dataset <--> task mismatch for datasets with metadatacol_mapping = {}if selected_task in ["binary_classification", "multi_class_classification"]:with col1:4 unmodified linesst.text("")st.markdown("`target` column")with col2:text_col = st.selectbox("This column should contain the text you want to classify",col_names,index=col_names.index(get_key(metadata[0]["col_mapping"], "text")) if metadata is not None else 0,)target_col = st.selectbox("This column should contain the labels you want to assign to the text",col_names,index=col_names.index(get_key(metadata[0]["col_mapping"], "target")) if metadata is not None else 0,)col_mapping[text_col] = "text"col_mapping[target_col] = "target"10 unmodified linestokens_col = st.selectbox("This column should contain the parts of the text (as an array of tokens) you want to assign labels to",col_names,index=col_names.index(get_key(metadata[0]["col_mapping"], "tokens")) if metadata is not None else 0,)tags_col = st.selectbox("This column should contain the labels to associate to each part of the text",col_names,index=col_names.index(get_key(metadata[0]["col_mapping"], "tags")) if metadata is not None else 0,)col_mapping[tokens_col] = "tokens"col_mapping[tags_col] = "tags"7 unmodified linesst.text("")st.markdown("`target` column")with col2:text_col = st.selectbox("This column should contain the text you want to translate",col_names,index=col_names.index(get_key(metadata[0]["col_mapping"], "source")) if metadata is not None else 0,)target_col = st.selectbox("This column should contain an example translation of the source text",col_names,index=col_names.index(get_key(metadata[0]["col_mapping"], "target")) if metadata is not None else 0,)col_mapping[text_col] = "source"col_mapping[target_col] = "target"7 unmodified linesst.text("")st.markdown("`target` column")with col2:text_col = st.selectbox("This column should contain the text you want to summarize",col_names,index=col_names.index(get_key(metadata[0]["col_mapping"], "text")) if metadata is not None else 0,)target_col = st.selectbox("This column should contain an example summarization of the text",col_names,index=col_names.index(get_key(metadata[0]["col_mapping"], "target")) if metadata is not None else 0,)col_mapping[text_col] = "text"col_mapping[target_col] = "target"16 unmodified linesst.text("")st.markdown("`answers.answer_start` column")with col2:context_col = st.selectbox("This column should contain the question's context",col_names,index=col_names.index(get_key(metadata[0]["col_mapping"], "context")) if metadata is not None else 0,)question_col = st.selectbox("This column should contain the question to be answered, given the context",col_names,index=col_names.index(get_key(metadata[0]["col_mapping"], "question")) if metadata is not None else 0,)answers_text_col = st.selectbox("This column should contain example answers to the question, extracted from the context",col_names,index=col_names.index(get_key(metadata[0]["col_mapping"], "answers.text"))if metadata is not Noneelse 0,)answers_start_col = st.selectbox("This column should contain the indices in the context of the first character of each answers.text",col_names,index=col_names.index(get_key(metadata[0]["col_mapping"], "answers.answer_start"))if metadata is not Noneelse 0,)col_mapping[context_col] = "context"col_mapping[question_col] = "question"4 unmodified linescompatible_models = get_compatible_models(selected_task, selected_dataset)selected_models = st.multiselect("Select the models you wish to evaluate", compatible_models)print("Selected models:", selected_models)submit_button = st.form_submit_button("Make submission")if submit_button:
47 unmodified lines484950515253545556575 unmodified lines63646547 unmodified linesdef get_metadata(dataset_name: str) -> Union[Dict, None]:filt = DatasetFilter(dataset_name=dataset_name)data = api.list_datasets(filter=filt, full=True)if data[0].cardData is not None and "train-eval-index" in data[0].cardData.keys():return data[0].cardData["train-eval-index"]else:return None5 unmodified lines)compatible_models = api.list_models(filter=filt)return [model.modelId for model in compatible_models]47 unmodified lines4849505152535455565 unmodified lines626364656667686970717247 unmodified linesdef get_metadata(dataset_name: str) -> Union[Dict, None]:data = requests.get(f"https://huggingface.co/api/datasets/{dataset_name}").json()if data["cardData"] is not None and "train-eval-index" in data["cardData"].keys():return data["cardData"]["train-eval-index"]else:return None5 unmodified lines)compatible_models = api.list_models(filter=filt)return [model.modelId for model in compatible_models]def get_key(col_mapping, val):for key, value in col_mapping.items():if val == value:return keyreturn "key doesn't exist"
app.py+65-26
utils.py+11-4