Spaces:
Runtime error
Runtime error
File size: 7,121 Bytes
9994065 ac6c40f 8c3bdec ac6c40f 8c3bdec ac6c40f 9994065 ac6c40f a735144 5cd2405 a735144 ac6c40f 9994065 ac6c40f 9994065 ac6c40f 9994065 0ea4f6d 9994065 ac6c40f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
import json
import re
from datetime import datetime
import datacards
from datacards import (
considerations_page,
considerations_summary,
context_page,
context_summary,
curation_page,
curation_summary,
gem_page,
gem_summary,
overview_page,
overview_summary,
results_page,
results_summary,
)
import streamlit as st
##################
## streamlit
##################
st.set_page_config(
page_title="GEM Data Card Input Form",
page_icon="https://avatars.githubusercontent.com/u/72612128",
layout="wide",
initial_sidebar_state="auto",
)
page_description = """
# GEM Data Card Input Form
This application was designed for GEM.
It allows users to fill out all of the information going into the data documentation when submitting a new dataset.
Use the left sidebar to navigate:
- "**Dataset at a Glance**" shows selected information and tracks progress
- Each of the "**Section:**" pages opens a form for a specific section of the card
- Go to "**Review and Save**" when you are done to save your data card
Please use **markdown** formatting for each field.
"""
_N_FIELDS = datacards.considerations.N_FIELDS + \
datacards.context.N_FIELDS + \
datacards.curation.N_FIELDS + \
datacards.gem.N_FIELDS + \
datacards.overview.N_FIELDS + \
datacards.results.N_FIELDS
def main():
if "save_state" not in st.session_state:
st.session_state.save_state = {}
if "card_dict" not in st.session_state:
st.session_state.card_dict = {}
st.sidebar.markdown(page_description, unsafe_allow_html=True)
pages = {
"Dataset at a Glance": glance_page,
"Section: Dataset Overview": overview_page,
"Section: Dataset Curation": curation_page,
"Section: Dataset in GEM": gem_page,
"Section: Previous Results": results_page,
"Section: Considerations for Using Data": considerations_page,
"Section: Broader Social Context": context_page,
"Review and Save": review_page,
}
app_mode = st.sidebar.radio(
label="Navigation menu:",
options=list(pages.keys()),
index=0,
)
with st.sidebar.expander("Save or Load your work"):
# Save intermediary state
current_date = datetime.now().strftime(
"%m/%d/%Y, %H:%M:%S"
)
friendly_date = re.sub(
r"[^\w\s]", "_", current_date
).replace(" ", "_").replace("__", "_").replace("-", "")
st.download_button(
label="Save Intermediary Card State",
data=json.dumps(st.session_state.get("card_dict", {}), indent=2),
file_name=f"data_card_{friendly_date}.json",
)
# load from file
uploaded_file = st.file_uploader(
label=f"Load Intermediary Card State",
)
if uploaded_file is not None:
pre_card_dict = json.load(uploaded_file, encoding="utf-8")
def save_dict_to_save_state(saved, prefix=None):
prefix = [] if prefix is None else prefix
if isinstance(saved, dict):
for k, v in saved.items():
save_dict_to_save_state(v, prefix + [k])
else:
if not st.session_state.save_state.get("_".join(prefix) + "_filled", False):
st.session_state.save_state["_".join(prefix)] = saved
# TODO: don't overwrite by default
st.session_state.card_dict = pre_card_dict
save_dict_to_save_state(st.session_state.card_dict)
# TODO: delete file after use
st.markdown("#### GEM Data Card Input Form")
pages[app_mode]()
def glance_page():
with st.expander("Dataset at a Glance", expanded=True):
dataset_summary = ""
dataset_summary += f"- **Dataset Website**: {st.session_state.save_state.get('overview_where_website', '*Go to `Section: Dataset Overview` to fill in*')}\n"
dataset_summary += f"- **Dataset Contact**: {st.session_state.save_state.get('overview_where_contact-name', '*Go to `Section: Dataset Overview` to fill in*')}\n"
dataset_summary += f"- **Dataset License**: {st.session_state.save_state.get('overview_languages_license', '*Go to `Section: Dataset Overview` to fill in*')}\n"
dataset_summary += f"- **Multilingual Dataset**: {st.session_state.save_state.get('overview_languages_is-multilingual', '*Go to `Section: Dataset Overview` to fill in*')}\n"
dataset_summary += f"- **Dataset Languages**: {st.session_state.save_state.get('overview_languages_language-names', '*Go to `Section: Dataset Overview` to fill in*')}\n"
dataset_summary += f"- **Dataset Supported Task**: {st.session_state.save_state.get('overview_languages_task', '*Go to `Section: Dataset Overview` to fill in*')}\n"
dataset_summary += f"- **Communicative Goal**: {st.session_state.save_state.get('overview_languages_communicative', '*Go to `Section: Dataset Overview` to fill in*')}\n"
dataset_summary += f"- **Language Data Origin**: {st.session_state.save_state.get('curation_language_obtained', '*Go to `Section: Dataset Curation` to fill in*')}\n"
dataset_summary += f"- **Annotation Data Origin**: {st.session_state.save_state.get('curation_annotations_obtained', '*Go to `Section: Dataset Curation` to fill in*')}\n"
dataset_summary += f"- **Likelihood of PII**: {st.session_state.save_state.get('curation_pii_has-pii', '*Go to `Section: Dataset Curation` to fill in*')}\n"
st.markdown(dataset_summary + "---\n")
num_fields = sum([len(dct) for k in st.session_state.get("card_dict", {}) for dct in st.session_state.card_dict.get(k, {}).values()])
st.markdown(f"You have currently filled out **{num_fields} of {_N_FIELDS} required fields** in the data card.")
left_col, right_col = st.columns(2)
with left_col:
overview_summary()
curation_summary()
gem_summary()
with right_col:
results_summary()
considerations_summary()
context_summary()
def review_page():
dataset_name = st.text_input(
label="Enter dataset name here",
)
if dataset_name != "":
friendly_name = re.sub(
r"[^\w\s]", " ", dataset_name.lower()
).strip().replace(" ", "_")
current_date = datetime.now().strftime(
"%m/%d/%Y, %H:%M:%S"
)
friendly_date = re.sub(
r"[^\w\s]", "_", current_date
).replace(" ", "_").replace("__", "_").replace("-", "")
dataset_file_name = f"{friendly_name}-{friendly_date}.json"
st.download_button(
label=f"Download the Dataset Card below as {dataset_file_name}",
data=json.dumps(st.session_state.get("card_dict", {}), indent=2),
file_name=dataset_file_name,
)
else:
st.markdown("##### Enter a dataset name above to be able to download the card!")
st.markdown("---\n")
st.write(st.session_state.get("card_dict", {}))
# TODO add buttons to save and download
if __name__ == "__main__":
main()
|