Imane Momayiz commited on
Commit
5ef45dd
1 Parent(s): 2ce4d20

fix: sumbimissions saving

Browse files
Files changed (1) hide show
  1. app.py +63 -68
app.py CHANGED
@@ -62,73 +62,68 @@ def store_submission(api: HfApi, sentence: str, translation: str, translation_fr
62
  dataset = load_data(REPO_ID)
63
 
64
 
65
- def main():
66
-
67
- if "sentence" not in st.session_state:
68
- st.session_state.sentence = fetch_sentence(dataset)
69
- if 'translation_input' not in st.session_state:
70
- st.session_state.translation_input = ""
71
- if 'translation_input_fr' not in st.session_state:
72
- st.session_state.translation_input_fr = ""
73
- if 'display_new' not in st.session_state:
74
- st.session_state.display_new = False
75
-
76
- st.title("Translate From Arabic to English")
77
-
78
- st.markdown(
79
- """This mini-app allows you to contribute to the **darija-english** dataset
80
- as part of [DODa](https://darija-open-dataset.github.io/)
81
- project. To contribute, simply translate the given sentence from Arabic to English.
82
- The translated sentence will be submitted to the dataset
83
- [here](https://huggingface.co/datasets/imomayiz/darija-english)."""
84
- )
85
-
86
- st.text("")
87
-
88
- st.write(f"""
89
- <div style="
90
- padding: 5px;
91
- border: 1px solid #000000;
92
- border-radius: 5px;
93
- ">
94
- <p style="font-size: 20px;">{st.session_state.sentence}.</p>
95
- </div>""", unsafe_allow_html=True)
96
-
97
-
98
- # Display new sentence button
99
- st.session_state.display_new = st.button("New Sentence",
100
- on_click=fetch_sentence,
101
- args=(dataset,))
102
 
103
 
104
- # Input field for translation
105
- translation_input_placeholder = st.empty()
106
-
107
- with translation_input_placeholder.container():
108
- translation_input = st.text_input("Enter translation to english: ",
109
- st.session_state.translation_input)
110
- st.session_state.translation_input = translation_input
111
-
112
- # Input field for translation
113
- translation_input_placeholder_fr = st.empty()
114
-
115
- with translation_input_placeholder_fr.container():
116
- translation_input_fr = st.text_input(
117
- "Enter translation to darija in latin characters: ",
118
- st.session_state.translation_input_fr
119
- )
120
- st.session_state.translation_input_fr = translation_input_fr
121
-
122
- # Submit button
123
- if st.button("Submit Translation"):
124
- if not translation_input and translation_input_fr:
125
- st.warning("Please enter a translation before submitting.")
126
- else:
127
- store_submission(api,
128
- st.session_state.sentence,
129
- st.session_state.translation_input,
130
- st.session_state.translation_input_fr
131
- )
132
-
133
- if __name__ == "__main__":
134
- main()
 
 
 
 
62
  dataset = load_data(REPO_ID)
63
 
64
 
65
+ if "sentence" not in st.session_state:
66
+ st.session_state.sentence = fetch_sentence(dataset)
67
+ if 'translation_input' not in st.session_state:
68
+ st.session_state.translation_input = ""
69
+ if 'translation_input_fr' not in st.session_state:
70
+ st.session_state.translation_input_fr = ""
71
+ if 'display_new' not in st.session_state:
72
+ st.session_state.display_new = False
73
+
74
+ st.title("Translate From Arabic to English")
75
+
76
+ st.markdown(
77
+ """This mini-app allows you to contribute to the **darija-english** dataset
78
+ as part of [DODa](https://darija-open-dataset.github.io/)
79
+ project. To contribute, simply translate the given sentence from Arabic to English.
80
+ The translated sentence will be submitted to the dataset
81
+ [here](https://huggingface.co/datasets/imomayiz/darija-english)."""
82
+ )
83
+
84
+ st.text("")
85
+
86
+ st.write(f"""
87
+ <div style="
88
+ padding: 5px;
89
+ border: 1px solid #000000;
90
+ border-radius: 5px;
91
+ ">
92
+ <p style="font-size: 20px;">{st.session_state.sentence}.</p>
93
+ </div>""", unsafe_allow_html=True)
 
 
 
 
 
 
 
 
94
 
95
 
96
+ # Display new sentence button
97
+ st.session_state.display_new = st.button("New Sentence",
98
+ on_click=fetch_sentence,
99
+ args=(dataset,))
100
+
101
+
102
+ # Input field for translation
103
+ translation_input_placeholder = st.empty()
104
+
105
+ with translation_input_placeholder.container():
106
+ translation_input = st.text_input("Enter translation to english: ",
107
+ st.session_state.translation_input)
108
+ st.session_state.translation_input = translation_input
109
+
110
+ # Input field for translation
111
+ translation_input_placeholder_fr = st.empty()
112
+
113
+ with translation_input_placeholder_fr.container():
114
+ translation_input_fr = st.text_input(
115
+ "Enter translation to darija in latin characters: ",
116
+ st.session_state.translation_input_fr
117
+ )
118
+ st.session_state.translation_input_fr = translation_input_fr
119
+
120
+ # Submit button
121
+ if st.button("Submit Translation"):
122
+ if not translation_input and translation_input_fr:
123
+ st.warning("Please enter a translation before submitting.")
124
+ else:
125
+ store_submission(api,
126
+ st.session_state.sentence,
127
+ st.session_state.translation_input,
128
+ st.session_state.translation_input_fr
129
+ )