shrut27 commited on
Commit
7ac3970
1 Parent(s): 1e78c02

Upload 4 files

Browse files
Files changed (4) hide show
  1. Procfile +2 -0
  2. app.py +58 -0
  3. requirements.txt +16 -0
  4. setup.sh +7 -0
Procfile ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ web: sh setup.sh && streamlit run app.py
2
+
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from googletrans import Translator
3
+ from gtts import gTTS
4
+ from IPython.display import Audio
5
+
6
+ # Create an instance of Translator
7
+ translator = Translator()
8
+
9
+ # Set up the Streamlit app
10
+ st.title("Translator with Audio Output")
11
+ st.write("Enter text in the box below and select the language to translate to.")
12
+
13
+ # Create a text input box for the user to enter text
14
+ text = st.text_input("Enter text here:")
15
+
16
+ # Create a dropdown menu for selecting the language to translate to
17
+ languages = {
18
+ "Afrikaans": "af",
19
+ "Arabic": "ar",
20
+ "Bengali": "bn",
21
+ "Chinese (Simplified)": "zh-cn",
22
+ "Chinese (Traditional)": "zh-tw",
23
+ "Dutch": "nl",
24
+ "French": "fr",
25
+ "German": "de",
26
+ "Greek": "el",
27
+ "Hindi": "hi",
28
+ "Italian": "it",
29
+ "Japanese": "ja",
30
+ "Korean": "ko",
31
+ "Portuguese": "pt",
32
+ "Russian": "ru",
33
+ "Spanish": "es",
34
+ "Swedish": "sv",
35
+ "Turkish": "tr"
36
+ }
37
+
38
+ target_language = st.selectbox("Select language:", list(languages.keys()))
39
+
40
+ # Translate the text when the user clicks the "Translate" button
41
+ if st.button("Translate"):
42
+ if text:
43
+ translation = translator.translate(text, dest=languages[target_language])
44
+ st.write(f"Translated text ({target_language}):")
45
+ st.write(translation.text)
46
+
47
+ # Generate audio file of translated text
48
+ tts = gTTS(text=translation.text, lang=languages[target_language])
49
+ audio_file = "translation.mp3"
50
+ tts.save(audio_file)
51
+
52
+ # Display audio player in the app
53
+ audio_bytes = open(audio_file, "rb").read()
54
+ st.audio(audio_bytes, format="audio/mp3")
55
+
56
+ else:
57
+ st.write("Please enter some text to translate.")
58
+
requirements.txt ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ altair==4.2.0
2
+ ecos==2.0.10
3
+ entrypoints==0.4
4
+ GitPython==3.1.29
5
+ google==3.0.0
6
+ google-auth==2.17.2
7
+ google-auth-oauthlib==1.0.0
8
+ google-search-results==2.4.2
9
+ googletrans==4.0.0rc1
10
+ gTTS==2.3.1
11
+ h11==0.9.0
12
+ h2==3.2.0
13
+ huggingface-hub==0.13.3
14
+ ipython==8.5.0
15
+ streamlit==1.16.0
16
+
setup.sh ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ mkdir -p ~/.streamlit
2
+
3
+ echo "[server]
4
+ headless = true
5
+ port = $PORT
6
+ enableCORS = false
7
+ " > ~/.streamlit/config.toml