|
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 |
|
|
|
|
|
HF_API_KEY = os.environ.get("HF_TOKEN", None) |
|
api = HfApi(token=HF_API_KEY) |
|
os.makedirs(submissions_folder, exist_ok=True) |
|
|
|
|
|
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, |
|
) |
|
|
|
|
|
st.set_page_config(page_title="DODa", |
|
page_icon=DODA_LOGO,) |
|
|
|
|
|
st.image(DODA_LOGO, use_column_width=True) |
|
|
|
|
|
dataset = load_data(REPO_ID) |
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
|
st.title("DODa Labeling App") |
|
|
|
st.markdown(INTRO_TEXT, unsafe_allow_html=True) |
|
|
|
st.divider() |
|
|
|
st.write(f""" |
|
<div style=" |
|
padding: 5px; |
|
border: 1px solid #000000; |
|
border-radius: 5px; |
|
"> |
|
<p style="font-size: 20px;">{st.session_state.sentence}.</p> |
|
</div>""", unsafe_allow_html=True) |
|
|
|
|
|
|
|
st.session_state.display_new = st.button("Generate a new sentence", |
|
on_click=fetch_sentence, |
|
args=(dataset,)) |
|
|
|
|
|
|
|
translation_input = st.text_input( |
|
"Enter translation to english: ", |
|
st.session_state.translation_input |
|
) |
|
|
|
|
|
translation_input_fr = st.text_input( |
|
"Enter translation to darija in latin characters: ", |
|
st.session_state.translation_input_fr |
|
) |
|
|
|
st.session_state.translation_input = translation_input |
|
st.session_state.translation_input_fr = translation_input_fr |
|
|
|
print(st.session_state.sentence) |
|
print(st.session_state.translation_input) |
|
print(st.session_state.translation_input_fr) |
|
|
|
|
|
submit_button = st.button("Submit Translation") |
|
if submit_button: |
|
if st.session_state.translation_input_fr or st.session_state.translation_input: |
|
store_submission(scheduler, |
|
st.session_state.sentence, |
|
st.session_state.translation_input, |
|
st.session_state.translation_input_fr |
|
) |
|
_ = fetch_sentence(dataset) |
|
else: |
|
st.warning("Please enter a translation before submitting.") |