Spaces:
Runtime error
Runtime error
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 to support the GEM v2 data hackathon. | |
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 | |
""" | |
_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 in GEM": gem_page, | |
"Section: Dataset Curation": curation_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, | |
) | |
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', '')}\n" | |
dataset_summary += f"- **Dataset Contact**: {st.session_state.save_state.get('overview_where_contact-name', '')}\n" | |
dataset_summary += f"- **Dataset License**: {st.session_state.save_state.get('overview_languages_license', '')}\n" | |
dataset_summary += f"- **Multilingual Dataset**: {st.session_state.save_state.get('overview_languages_is-multilingual', '')}\n" | |
dataset_summary += f"- **Dataset Languages**: {', '.join(st.session_state.save_state.get('overview_languages_language-names', []))}\n" | |
dataset_summary += f"- **Dataset Supported Task**: {st.session_state.save_state.get('overview_languages_task', '')}\n" | |
dataset_summary += f"- **Communicative Goal**: {st.session_state.save_state.get('dataset_communicative', '')}\n" | |
dataset_summary += f"- **Language Data Origin**: {st.session_state.save_state.get('curation_language_origin', '')}\n" | |
dataset_summary += f"- **Annotation Data Origin**: {st.session_state.save_state.get('curation_annotation_origin', '')}\n" | |
dataset_summary += f"- **Likelihood of PII**: {st.session_state.save_state.get('pii_likelihood', '')}\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() | |
gem_summary() | |
curation_summary() | |
with right_col: | |
results_summary() | |
considerations_summary() | |
context_summary() | |
def review_page(): | |
st.write(st.session_state.get("card_dict", {})) | |
# TODO add buttons to save and download | |
if __name__ == "__main__": | |
main() | |