import os import streamlit as st from huggingface_hub import HfApi, CommitScheduler from src.components import ( load_data, fetch_sentence, store_submission, REPO_ID, submissions_folder) from src.layout import INTRO_TEXT, DODA_LOGO # setup HF_API_KEY = os.environ.get("HF_TOKEN", None) api = HfApi(token=HF_API_KEY) os.makedirs(submissions_folder, exist_ok=True) # Create a commit scheduler scheduler = CommitScheduler( token=HF_API_KEY, hf_api=api, repo_id=REPO_ID, repo_type="dataset", folder_path=submissions_folder, path_in_repo=submissions_folder, every=10, ) # Load the dataset dataset = load_data(REPO_ID) # Initialize session state if "sentence" not in st.session_state: st.session_state.sentence = fetch_sentence(dataset) if 'translation_input' not in st.session_state: st.session_state.translation_input = "" if 'translation_input_fr' not in st.session_state: st.session_state.translation_input_fr = "" if 'display_new' not in st.session_state: st.session_state.display_new = False # Set page config st.set_page_config(page_title="DODa", page_icon=DODA_LOGO,) # add an image st.image(DODA_LOGO, use_column_width=True) # title st.title("DODa Labeling App") st.markdown(INTRO_TEXT, unsafe_allow_html=True) st.divider() st.write(f"""

{st.session_state.sentence}.

""", unsafe_allow_html=True) # Display new sentence button st.session_state.display_new = st.button("New Sentence", on_click=fetch_sentence, args=(dataset,)) # Input field for translation translation_input = st.text_input( "Enter translation to english: ", st.session_state.translation_input ) st.session_state.translation_input = translation_input # Input field for translation in latin characters translation_input_fr = st.text_input( "Enter translation to darija in latin characters: ", st.session_state.translation_input_fr ) st.session_state.translation_input_fr = translation_input_fr # Save states before refreshing the page sentence = st.session_state.sentence translation_input = st.session_state.translation_input translation_input_fr = st.session_state.translation_input_fr submit_button = st.button("Submit Translation", on_click=fetch_sentence, args=(dataset,)) if submit_button: if translation_input_fr or translation_input: store_submission(scheduler, sentence, translation_input, translation_input_fr ) else: st.warning("Please enter a translation before submitting.")