Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,216 +1,212 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
from deep_translator import GoogleTranslator
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
import
|
7 |
-
import
|
8 |
-
|
9 |
-
from
|
10 |
-
import
|
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 |
-
st.
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
st.session_state.
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
#
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
st.
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
background-color:
|
202 |
-
color: white;
|
203 |
-
}
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
""
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
if selected == "Tone":
|
214 |
-
tone()
|
215 |
-
if selected == "About":
|
216 |
about.about_page()
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from deep_translator import GoogleTranslator
|
3 |
+
|
4 |
+
import os
|
5 |
+
|
6 |
+
from streamlit_option_menu import option_menu
|
7 |
+
import css
|
8 |
+
|
9 |
+
from voice import transcribe,text_to_speech
|
10 |
+
from tone import tone
|
11 |
+
import about
|
12 |
+
|
13 |
+
os.environ["STREAMLIT_WATCHER_TYPE"] = "none"
|
14 |
+
st.session_state.translate=False
|
15 |
+
|
16 |
+
st.set_page_config(page_title="VoiceBridge",layout="wide",page_icon="fevicon.png")
|
17 |
+
Languages = {'afrikaans':'af','albanian':'sq','amharic':'am','arabic':'ar','armenian':'hy','azerbaijani':'az',
|
18 |
+
'basque':'eu','belarusian':'be','bengali':'bn','bosnian':'bs','bulgarian':'bg','catalan':'ca',
|
19 |
+
'cebuano':'ceb','chichewa':'ny','chinese (simplified)':'zh-cn','chinese (traditional)':'zh-tw',
|
20 |
+
'corsican':'co','croatian':'hr','czech':'cs','danish':'da','dutch':'nl','english':'en','esperanto':'eo',
|
21 |
+
'estonian':'et','filipino':'tl','finnish':'fi','french':'fr','frisian':'fy','galician':'gl','georgian':'ka',
|
22 |
+
'german':'de','greek':'el','gujarati':'gu','haitian creole':'ht','hausa':'ha','hawaiian':'haw','hebrew':'iw',
|
23 |
+
'hebrew':'he','hindi':'hi','hmong':'hmn','hungarian':'hu','icelandic':'is','igbo':'ig','indonesian':'id',
|
24 |
+
'irish':'ga','italian':'it','japanese':'ja','javanese':'jw','kannada':'kn','kazakh':'kk','khmer':'km',
|
25 |
+
'korean':'ko','kurdish (kurmanji)':'ku','kyrgyz':'ky','lao':'lo','latin':'la','latvian':'lv','lithuanian':'lt',
|
26 |
+
'luxembourgish':'lb','macedonian':'mk','malagasy':'mg','malay':'ms','malayalam':'ml','maltese':'mt','maori':'mi',
|
27 |
+
'marathi':'mr','mongolian':'mn','myanmar (burmese)':'my','nepali':'ne','norwegian':'no','odia':'or','pashto':'ps',
|
28 |
+
'persian':'fa','polish':'pl','portuguese':'pt','punjabi':'pa','romanian':'ro','russian':'ru','samoan':'sm',
|
29 |
+
'scots gaelic':'gd','serbian':'sr','sesotho':'st','shona':'sn','sindhi':'sd','sinhala':'si','slovak':'sk',
|
30 |
+
'slovenian':'sl','somali':'so','spanish':'es','sundanese':'su','swahili':'sw','swedish':'sv','tajik':'tg',
|
31 |
+
'tamil':'ta','telugu':'te','thai':'th','turkish':'tr','turkmen':'tk','ukrainian':'uk','urdu':'ur','uyghur':'ug',
|
32 |
+
'uzbek':'uz','vietnamese':'vi','welsh':'cy','xhosa':'xh','yiddish':'yi','yoruba':'yo','zulu':'zu'}
|
33 |
+
|
34 |
+
|
35 |
+
|
36 |
+
st.markdown(
|
37 |
+
"""
|
38 |
+
<style>
|
39 |
+
|
40 |
+
[alt="Logo"] {
|
41 |
+
height: 90px;
|
42 |
+
width: auto;
|
43 |
+
|
44 |
+
}
|
45 |
+
.block-container {
|
46 |
+
padding-top: 0rem;
|
47 |
+
}
|
48 |
+
header { visibility: hidden; }
|
49 |
+
</style>
|
50 |
+
""",
|
51 |
+
unsafe_allow_html=True
|
52 |
+
)
|
53 |
+
col1, col2 = st.columns([1, 6])
|
54 |
+
with col1:
|
55 |
+
st.markdown("""
|
56 |
+
<style>
|
57 |
+
@media only screen and (max-width: 959px) {
|
58 |
+
img {
|
59 |
+
max-width: 100px;
|
60 |
+
height: auto;
|
61 |
+
}
|
62 |
+
}
|
63 |
+
</style>
|
64 |
+
""", unsafe_allow_html=True)
|
65 |
+
st.logo("logo.png")
|
66 |
+
with col2:
|
67 |
+
|
68 |
+
css.nev()
|
69 |
+
st.markdown('<div class="custom-navbar">', unsafe_allow_html=True)
|
70 |
+
selected = option_menu(
|
71 |
+
menu_title=None,
|
72 |
+
options=["Translate", "Tone", "About"],
|
73 |
+
icons=["bi-people-fill", "bi-soundwave", "gear"],
|
74 |
+
menu_icon="cast",
|
75 |
+
default_index=0,
|
76 |
+
orientation="horizontal",
|
77 |
+
styles={
|
78 |
+
"container": {"padding": "0!important", "background-color": "#0E1117"},
|
79 |
+
"icon": {"color": "white"},
|
80 |
+
"nav-link": {
|
81 |
+
"text-align": "center",
|
82 |
+
"margin": "0px",
|
83 |
+
"--hover-color": "#204044",
|
84 |
+
},
|
85 |
+
"nav-link-selected": {"background-color": "#1f6f78"},
|
86 |
+
}
|
87 |
+
)
|
88 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
89 |
+
with st.container():
|
90 |
+
st.markdown("""
|
91 |
+
<style>
|
92 |
+
.custom-container {
|
93 |
+
margin-top: 70px;
|
94 |
+
}
|
95 |
+
|
96 |
+
@media (max-width: 767px) {
|
97 |
+
.custom-container {
|
98 |
+
margin-top: 0px;
|
99 |
+
}
|
100 |
+
}
|
101 |
+
</style>
|
102 |
+
<style>
|
103 |
+
.middle {
|
104 |
+
margin-top: 120px;
|
105 |
+
}
|
106 |
+
|
107 |
+
@media (max-width: 767px) {
|
108 |
+
.middle {
|
109 |
+
margin-top: 0px;
|
110 |
+
}
|
111 |
+
}
|
112 |
+
</style>
|
113 |
+
""", unsafe_allow_html=True)
|
114 |
+
st.markdown('<div class="custom-container">', unsafe_allow_html=True)
|
115 |
+
|
116 |
+
left_col, st.session_state.mid_col, st.session_state.right_col = st.columns([3, 2, 3])
|
117 |
+
# left user input
|
118 |
+
# ------------------------------------------------------------------------------------------------------------------------------------------------
|
119 |
+
if (selected == "Translate" or selected == "Tone"):
|
120 |
+
with left_col:
|
121 |
+
with st.popover("", icon=":material/tune:"):
|
122 |
+
inp = st.selectbox('Choose Input Format', ("Text", "Audio_file", "MIC"))
|
123 |
+
st.session_state.inp = inp
|
124 |
+
with st.form("my_form"):
|
125 |
+
st.markdown("### 🎙️ Input")
|
126 |
+
if st.session_state.inp == "Text":
|
127 |
+
st.session_state.text = st.text_area("Enter Text:", help="Type your text here...")
|
128 |
+
elif st.session_state.inp == "MIC":
|
129 |
+
st.session_state.uploaded_file = st.audio_input("Record a Voice Message")
|
130 |
+
else:
|
131 |
+
st.session_state.uploaded_file = st.file_uploader("Upload an Audio File", type=["mp3", "wav", "m4a"])
|
132 |
+
|
133 |
+
submitted = st.form_submit_button("Submit")
|
134 |
+
|
135 |
+
# ------------------------------------------------------------------------------------------------------------------------------------------------
|
136 |
+
if selected == "Translate":
|
137 |
+
|
138 |
+
# ------------------------------------------------------------------------------------------------------------------------------------------------
|
139 |
+
# center button
|
140 |
+
st.markdown('<div class="middle">', unsafe_allow_html=True)
|
141 |
+
with st.session_state.mid_col:
|
142 |
+
|
143 |
+
css.cicle_button()
|
144 |
+
|
145 |
+
if st.button("Translate"):
|
146 |
+
st.session_state.translate=False
|
147 |
+
st.session_state.translate=True
|
148 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
149 |
+
|
150 |
+
|
151 |
+
# ------------------------------------------------------------------------------------------------------------------------------------------------
|
152 |
+
# Right Output
|
153 |
+
with st.session_state.right_col:
|
154 |
+
|
155 |
+
with st.popover("", icon=":material/tune:"):
|
156 |
+
out_type = st.selectbox('Choose Input Format', ("Text", "Voice", "Both"))
|
157 |
+
st.session_state.out_type = out_type
|
158 |
+
with st.form("output"):
|
159 |
+
st.markdown("### 🔉 Voice Output")
|
160 |
+
option2 = st.selectbox('Select Output Language', list(Languages.keys()))
|
161 |
+
value2 = Languages[option2]
|
162 |
+
|
163 |
+
if st.session_state.translate:
|
164 |
+
c1,c2=st.columns(2)
|
165 |
+
if st.session_state.inp != "Text":
|
166 |
+
st.session_state.text = transcribe(st.session_state.uploaded_file)
|
167 |
+
|
168 |
+
translated_text = GoogleTranslator(target=value2).translate(st.session_state.text)
|
169 |
+
|
170 |
+
if st.session_state.out_type == "Text":
|
171 |
+
st.text_area("Translated Text:", translated_text, height=100)
|
172 |
+
|
173 |
+
elif st.session_state.out_type == "Voice":
|
174 |
+
if translated_text.strip():
|
175 |
+
audio_file = text_to_speech(translated_text, value2)
|
176 |
+
else:
|
177 |
+
c2.warning("Please enter text before converting.")
|
178 |
+
st.audio(audio_file, format='audio/mp3', autoplay=True)
|
179 |
+
|
180 |
+
else:
|
181 |
+
if translated_text.strip():
|
182 |
+
audio_file = text_to_speech(translated_text, value2)
|
183 |
+
else:
|
184 |
+
c2.warning("Please enter text before converting.")
|
185 |
+
with c1.popover("", icon=":material/library_books:"):
|
186 |
+
st.text_area("Translated Text:", translated_text, height=100)
|
187 |
+
c2.audio(audio_file, format='audio/mp3', autoplay=True)
|
188 |
+
|
189 |
+
reset = st.form_submit_button("Reset ↻ ")
|
190 |
+
if reset:
|
191 |
+
st.session_state.translate= False
|
192 |
+
# Optional: Add some styling
|
193 |
+
st.markdown("""
|
194 |
+
|
195 |
+
<style>
|
196 |
+
body {
|
197 |
+
background-color: #0e1117;
|
198 |
+
color: white;
|
199 |
+
}
|
200 |
+
.stButton>button {
|
201 |
+
background-color: teal;
|
202 |
+
color: white;
|
203 |
+
}
|
204 |
+
</style>
|
205 |
+
""", unsafe_allow_html=True)
|
206 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
207 |
+
|
208 |
+
|
209 |
+
if selected == "Tone":
|
210 |
+
tone()
|
211 |
+
if selected == "About":
|
|
|
|
|
|
|
|
|
212 |
about.about_page()
|