mjawad17 commited on
Commit
eb03aa3
1 Parent(s): f836eb1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -71
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import streamlit as st
2
  from gtts import gTTS
3
  from io import BytesIO
 
4
 
5
  # Dictionary to map language codes to full names
6
  LANGUAGES = {
@@ -39,58 +40,6 @@ def text_to_speech(text, lang='en'):
39
  mp3_fp.seek(0)
40
  return mp3_fp
41
 
42
- # # Custom CSS for styling
43
- # st.markdown(
44
- # """
45
- # <style>
46
- # /* Background color for the whole app */
47
- # .stApp {
48
- # background-color: #f0f2f6;
49
- # color: #333333;
50
- # font-family: 'Arial', sans-serif;
51
- # }
52
-
53
- # /* Style for markdown headings */
54
- # h1, h2, h3, h4, h5, h6 {
55
- # color: #4B0082; /* Indigo color */
56
- # font-family: 'Verdana', sans-serif;
57
- # }
58
-
59
- # /* Style for the text area */
60
- # .stTextArea {
61
- # background-color: #ffffff; /* White background */
62
- # color: #333333; /* Dark text color */
63
- # border-radius: 10px;
64
- # border: 1px solid #cccccc;
65
- # }
66
-
67
- # /* Style for buttons */
68
- # .stButton button {
69
- # background-color: #4B0082; /* Indigo background */
70
- # color: #ffffff; /* White text */
71
- # border-radius: 5px;
72
- # border: none;
73
- # padding: 10px 20px;
74
- # font-size: 16px;
75
- # }
76
-
77
- # /* Style for selectbox */
78
- # .stSelectbox {
79
- # background-color: #ffffff;
80
- # color: #333333;
81
- # border-radius: 5px;
82
- # border: 1px solid #cccccc;
83
- # }
84
-
85
- # /* Divider line */
86
- # .stCaption {
87
- # border-top: 1px solid #cccc87;
88
- # }
89
- # </style>
90
- # """,
91
- # unsafe_allow_html=True
92
- # )
93
-
94
  # Custom CSS for gradient background
95
  st.markdown(
96
  """
@@ -106,12 +55,21 @@ st.markdown(
106
  # Streamlit app layout
107
  st.title("Text-to-Speech App")
108
 
109
- # Instruction for using the app in markdown
 
 
 
 
 
 
 
 
 
110
  st.markdown("### Instructions For Using App")
111
  st.markdown(
112
  """
113
  1. Enter the text you want to convert to speech in the text box below.
114
- 2. Select the language from the dropdown menu.
115
  3. Click the 'Convert to Speech' button to generate the audio file.
116
  4. Click the 'Download' button to download the audio file.
117
  """
@@ -121,30 +79,25 @@ st.caption("---")
121
  # Text input
122
  user_text = st.text_area("Enter your text:", "Hello, world!")
123
 
124
- # Language selection
125
- lang_code = st.selectbox(
126
- "Choose language",
127
- options=list(LANGUAGES.keys()),
128
- format_func=lambda x: LANGUAGES[x] # Display full name
129
- )
130
-
131
  # Initialize file variable
132
  audio_file = None
133
 
134
  # Convert text to speech and provide download button
135
  if st.button("Convert to Speech"):
136
  if user_text:
137
- audio_file = text_to_speech(user_text, lang_code)
138
- st.audio(audio_file, format='audio/mp3')
 
 
139
 
140
- # Make the audio file downloadable
141
- st.download_button(
142
- label="Download Audio",
143
- data=audio_file,
144
- file_name="output.mp3",
145
- mime="audio/mp3"
146
- )
147
  else:
148
  st.error("Please enter some text!")
149
 
150
- st.markdown("Developed by Muhammad Jawad.")
 
1
  import streamlit as st
2
  from gtts import gTTS
3
  from io import BytesIO
4
+ import time
5
 
6
  # Dictionary to map language codes to full names
7
  LANGUAGES = {
 
40
  mp3_fp.seek(0)
41
  return mp3_fp
42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  # Custom CSS for gradient background
44
  st.markdown(
45
  """
 
55
  # Streamlit app layout
56
  st.title("Text-to-Speech App")
57
 
58
+ # Sidebar for language selection and other options
59
+ st.sidebar.header("Options")
60
+ # Language selection
61
+ lang_code = st.sidebar.selectbox(
62
+ "Choose language",
63
+ options=list(LANGUAGES.keys()),
64
+ format_func=lambda x: LANGUAGES[x] # Display full name
65
+ )
66
+
67
+ # Instruction for using the app
68
  st.markdown("### Instructions For Using App")
69
  st.markdown(
70
  """
71
  1. Enter the text you want to convert to speech in the text box below.
72
+ 2. Select the language from the sidebar.
73
  3. Click the 'Convert to Speech' button to generate the audio file.
74
  4. Click the 'Download' button to download the audio file.
75
  """
 
79
  # Text input
80
  user_text = st.text_area("Enter your text:", "Hello, world!")
81
 
 
 
 
 
 
 
 
82
  # Initialize file variable
83
  audio_file = None
84
 
85
  # Convert text to speech and provide download button
86
  if st.button("Convert to Speech"):
87
  if user_text:
88
+ with st.spinner("Generating audio..."):
89
+ time.sleep(2) # 2-second loading simulation
90
+ audio_file = text_to_speech(user_text, lang_code)
91
+ st.audio(audio_file, format='audio/mp3')
92
 
93
+ # Make the audio file downloadable
94
+ st.download_button(
95
+ label="Download Audio",
96
+ data=audio_file,
97
+ file_name="output.mp3",
98
+ mime="audio/mp3"
99
+ )
100
  else:
101
  st.error("Please enter some text!")
102
 
103
+ st.markdown("Developed by Muhammad Jawad.")