Update app.py
Browse files
app.py
CHANGED
@@ -55,21 +55,21 @@ def main():
|
|
55 |
source_lang = detected_options[0][2] if detected_options[0][0] != "Auto-detect" else "Auto-detect"
|
56 |
source_lang_code = next((k for k, v in LANGUAGES.items() if v[1] == source_lang), "hi") if source_lang != "Auto-detect" else "auto"
|
57 |
source_options = ["Auto-detect"] + [f"{v[0]} ({v[1]})" for v in LANGUAGES.values()]
|
58 |
-
st.selectbox("Source", options=source_options, index=0 if source_lang == "Auto-detect" else source_options.index(f"{LANGUAGES[source_lang_code][0]} ({source_lang})"), key="source_lang"
|
59 |
input_text = st.text_area("Input Text", height=300, key="input_text", label_visibility="hidden")
|
60 |
input_type = st.radio("Input Type", ["Text", "File"], horizontal=True, label_visibility="hidden", key="input_type")
|
61 |
if input_type == "File":
|
62 |
st.file_uploader("Upload File", type=["txt", "docx", "pdf"], key="file_input", on_change=on_file_upload, label_visibility="hidden")
|
63 |
if st.session_state.get("file_input") and st.session_state.get("file_input").size >= 1024*1024:
|
64 |
st.error("File size must be less than 1 MB")
|
65 |
-
st.button("Translate", key="translate_btn", on_click=trigger_translation, args=(translation, lang_detect, audio_processor)
|
66 |
with col2:
|
67 |
source_lang_display = st.session_state.source_lang.split(" (")[0] if " (" in st.session_state.source_lang else st.session_state.source_lang
|
68 |
target_options = [f"{v[0]} ({v[1]})" for v in LANGUAGES.values() if v[0] != source_lang_display and v[1] != source_lang_display]
|
69 |
-
st.selectbox("Target", options=target_options, index=target_options.index(f"{LANGUAGES['en'][0]} ({LANGUAGES['en'][1]})") if "English" not in source_lang_display else 0, key="target_lang"
|
70 |
if "translated_text" in st.session_state:
|
71 |
st.text_area("Output Text", value=st.session_state.translated_text, height=300, key="output_text", disabled=True, label_visibility="hidden")
|
72 |
-
if st.button("🔊", key="audio_btn", on_click=play_audio, args=(audio_processor,), help="Play audio", use_container_width=False
|
73 |
pass
|
74 |
# Footer
|
75 |
if "translated_text" in st.session_state:
|
|
|
55 |
source_lang = detected_options[0][2] if detected_options[0][0] != "Auto-detect" else "Auto-detect"
|
56 |
source_lang_code = next((k for k, v in LANGUAGES.items() if v[1] == source_lang), "hi") if source_lang != "Auto-detect" else "auto"
|
57 |
source_options = ["Auto-detect"] + [f"{v[0]} ({v[1]})" for v in LANGUAGES.values()]
|
58 |
+
st.selectbox("Source Language", options=source_options, index=0 if source_lang == "Auto-detect" else source_options.index(f"{LANGUAGES[source_lang_code][0]} ({source_lang})"), key="source_lang")
|
59 |
input_text = st.text_area("Input Text", height=300, key="input_text", label_visibility="hidden")
|
60 |
input_type = st.radio("Input Type", ["Text", "File"], horizontal=True, label_visibility="hidden", key="input_type")
|
61 |
if input_type == "File":
|
62 |
st.file_uploader("Upload File", type=["txt", "docx", "pdf"], key="file_input", on_change=on_file_upload, label_visibility="hidden")
|
63 |
if st.session_state.get("file_input") and st.session_state.get("file_input").size >= 1024*1024:
|
64 |
st.error("File size must be less than 1 MB")
|
65 |
+
st.button("Translate", key="translate_btn", on_click=trigger_translation, args=(translation, lang_detect, audio_processor))
|
66 |
with col2:
|
67 |
source_lang_display = st.session_state.source_lang.split(" (")[0] if " (" in st.session_state.source_lang else st.session_state.source_lang
|
68 |
target_options = [f"{v[0]} ({v[1]})" for v in LANGUAGES.values() if v[0] != source_lang_display and v[1] != source_lang_display]
|
69 |
+
st.selectbox("Target Language", options=target_options, index=target_options.index(f"{LANGUAGES['en'][0]} ({LANGUAGES['en'][1]})") if "English" not in source_lang_display else 0, key="target_lang")
|
70 |
if "translated_text" in st.session_state:
|
71 |
st.text_area("Output Text", value=st.session_state.translated_text, height=300, key="output_text", disabled=True, label_visibility="hidden")
|
72 |
+
if st.button("🔊", key="audio_btn", on_click=play_audio, args=(audio_processor,), help="Play audio", use_container_width=False):
|
73 |
pass
|
74 |
# Footer
|
75 |
if "translated_text" in st.session_state:
|