File size: 2,764 Bytes
9481a42
d9514f5
eeeb878
d9514f5
 
 
b2e776f
eeeb878
d9514f5
9481a42
c5139c6
4821540
eeeb878
d9514f5
2c0f00c
 
 
 
 
 
 
b2e776f
2c0f00c
ae41ba2
d853c9c
 
 
 
 
 
 
9481a42
 
 
d9514f5
5ef45dd
 
 
 
 
 
 
 
 
b2e776f
 
 
 
5ef45dd
d9514f5
5ef45dd
eeeb878
5ef45dd
 
 
 
 
 
 
 
 
9481a42
 
5ef45dd
d853c9c
5ef45dd
 
 
 
 
d9514f5
1b7e918
d9514f5
 
5ef45dd
d9514f5
3c66851
1b7e918
5ef45dd
 
d853c9c
 
3c66851
5ef45dd
d853c9c
 
7f57b0a
d853c9c
bd96122
d853c9c
 
 
3c66851
d853c9c
3c66851
d853c9c
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
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,
)

# 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)

# 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



# title
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)
    

# Display new sentence button
st.session_state.display_new = st.button("Generate a new sentence",
                                            on_click=fetch_sentence,
                                            args=(dataset,))


# Input field for translation
translation_input = st.text_input(
    "Translate to english: ",
    st.session_state.translation_input
    )

# Input field for translation in latin characters
translation_input_fr = st.text_input(
        "Transcribe 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

# Save states before refreshing the page
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.")