File size: 2,520 Bytes
9481a42
d9514f5
eeeb878
d9514f5
 
 
 
eeeb878
d9514f5
9481a42
c5139c6
4821540
eeeb878
d9514f5
2c0f00c
 
 
 
 
 
 
 
 
ae41ba2
9481a42
 
 
d9514f5
5ef45dd
 
 
 
 
 
 
 
 
 
 
d9514f5
5ef45dd
eeeb878
5ef45dd
 
 
 
 
 
 
 
 
9481a42
 
5ef45dd
 
 
 
 
 
 
d9514f5
 
 
 
3c66851
5ef45dd
d9514f5
3c66851
5ef45dd
 
 
3c66851
5ef45dd
d9514f5
bcb5974
3c66851
bd96122
bcb5974
 
 
3c66851
 
 
 
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
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

# 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=1,
)

# 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

st.title("Translate From Arabic to English")

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("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

# Submit button
if st.button("Submit Translation"):
    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
                        )
    else:
        st.warning("Please enter a translation before submitting.")