Krishna086 commited on
Commit
891f160
·
verified ·
1 Parent(s): ffe41ab

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from translation import translate, LANGUAGES
3
+
4
+ # Main function for the app
5
+ def main():
6
+ # Set page title and description
7
+ st.title("Multilingual Translation App")
8
+ st.write("Translate text for multilingual support (e.g., chatbots or customer service).")
9
+
10
+ # Dropdowns for selecting languages
11
+ source_lang = st.selectbox("Source Language", list(LANGUAGES.keys()), index=0)
12
+ target_lang = st.selectbox("Target Language", list(LANGUAGES.keys()), index=1)
13
+
14
+ # Text input area
15
+ user_input = st.text_area("Input Text", placeholder="Enter text to translate...", height=150)
16
+
17
+ # Translate button
18
+ if st.button("Translate"):
19
+ if user_input:
20
+ # Show a spinner while translating
21
+ with st.spinner("Translating..."):
22
+ try:
23
+ # Call the translate function from translation.py
24
+ result = translate(user_input, source_lang, target_lang)
25
+ st.success("Translated Text:")
26
+ st.write(result)
27
+
28
+ # Show footer only after translation
29
+ st.markdown("""
30
+ <p style="font-size: small; color: grey; text-align: center;">
31
+ Developed By: Krishna Prakash
32
+ <a href="https://www.linkedin.com/in/krishnaprakash-profile/" target="_blank">
33
+ <img src="https://img.icons8.com/ios-filled/30/0077b5/linkedin.png" alt="LinkedIn" style="vertical-align: middle; margin: 0 5px;"/>
34
+ </a>
35
+ </p>
36
+ """, unsafe_allow_html=True)
37
+ except Exception as e:
38
+ # Show error if translation fails
39
+ st.error(f"Translation failed: {str(e)}")
40
+ else:
41
+ # Warn if no text is entered
42
+ st.warning("Please enter text to translate!")
43
+
44
+ # Run the app
45
+ if __name__ == "__main__":
46
+ main()