Prof-Hunter commited on
Commit
8ff117e
·
verified ·
1 Parent(s): b737285

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -105
app.py CHANGED
@@ -28,20 +28,21 @@ async def text_to_speech(text, voice, rate, pitch):
28
  if not voice:
29
  return None, "Please select a voice."
30
 
31
- voice_short_name = voice.split(" - ")[0]
32
 
33
  rate_str = f"{rate:+d}%"
34
  pitch_str = f"{pitch:+d}Hz"
35
 
36
  communicate = edge_tts.Communicate(
37
  text,
38
- voice_short_name,
39
  rate=rate_str,
40
  pitch=pitch_str,
41
  )
42
 
43
  with tempfile.NamedTemporaryFile(
44
- delete=False, suffix=".mp3"
 
45
  ) as tmp:
46
  path = tmp.name
47
  await communicate.save(path)
@@ -62,7 +63,7 @@ async def tts_interface(text, voice, rate, pitch):
62
 
63
 
64
  # -----------------------------
65
- # Custom Theme + CSS
66
  # -----------------------------
67
 
68
  SPJIMR_THEME = gr.themes.Base(
@@ -72,7 +73,6 @@ SPJIMR_THEME = gr.themes.Base(
72
  font=["Inter", "sans-serif"],
73
  )
74
 
75
-
76
  CUSTOM_CSS = """
77
  body {
78
  background: #FAF8F6 !important;
@@ -84,16 +84,7 @@ body {
84
  border-radius: 12px;
85
  color: white;
86
  text-align: center;
87
- }
88
-
89
- #header h1 {
90
- font-size: 32px;
91
- margin-bottom: 5px;
92
- }
93
-
94
- #header p {
95
- opacity: 0.9;
96
- font-size: 15px;
97
  }
98
 
99
  .card {
@@ -107,7 +98,6 @@ body {
107
  .section-title {
108
  color: #7A1E2D;
109
  font-weight: 600;
110
- margin-bottom: 10px;
111
  }
112
 
113
  .footer {
@@ -127,118 +117,80 @@ async def create_demo():
127
 
128
  voices = await get_voices()
129
 
130
- with gr.Blocks(
131
- theme=SPJIMR_THEME,
132
- css=CUSTOM_CSS,
133
- analytics_enabled=False,
134
- ) as demo:
135
 
136
- # -------------------------
137
  # Header
138
- # -------------------------
139
-
140
  gr.HTML("""
141
  <div id="header">
142
  <h1>🎙️ SPJIMR AI Voice Studio</h1>
143
- <p>Professional Text-to-Speech Generation Platform</p>
144
  </div>
145
  """)
146
 
147
- gr.Markdown("")
148
-
149
- # -------------------------
150
- # Main Panel
151
- # -------------------------
152
-
153
  with gr.Row():
154
 
155
- # Left: Input Panel
156
  with gr.Column(scale=5):
157
 
158
- with gr.HTML('<div class="card">'):
159
-
160
- gr.Markdown(
161
- "### 📝 Input",
162
- elem_classes="section-title",
163
- )
164
-
165
- text_input = gr.Textbox(
166
- label="Text Script",
167
- lines=7,
168
- placeholder="Enter lecture notes, podcast scripts, or narration text...",
169
- )
170
 
171
- voice_dropdown = gr.Dropdown(
172
- choices=[""] + list(voices.keys()),
173
- label="Voice Selection",
174
- value="",
175
- )
176
 
177
- gr.HTML("</div>")
 
 
 
 
178
 
179
 
180
- # Right: Controls
181
  with gr.Column(scale=4):
182
 
183
- with gr.HTML('<div class="card">'):
 
 
 
184
 
185
- gr.Markdown(
186
- "### 🎛️ Voice Controls",
187
- elem_classes="section-title",
188
- )
189
 
190
- rate_slider = gr.Slider(
191
- minimum=-50,
192
- maximum=50,
193
- value=0,
194
- step=1,
195
- label="Speech Rate (%)",
196
- )
197
 
198
- pitch_slider = gr.Slider(
199
- minimum=-20,
200
- maximum=20,
201
- value=0,
202
- step=1,
203
- label="Pitch (Hz)",
204
- )
205
 
206
- generate_btn = gr.Button(
207
- "Generate Audio",
208
- variant="primary",
209
- size="lg",
210
- )
211
 
212
- gr.HTML("</div>")
213
-
214
-
215
- # -------------------------
216
- # Output Panel
217
- # -------------------------
218
-
219
- with gr.HTML('<div class="card">'):
220
-
221
- gr.Markdown(
222
- "### 🔊 Output",
223
- elem_classes="section-title",
224
- )
225
-
226
- audio_output = gr.Audio(
227
- label="Generated Speech",
228
- type="filepath",
229
- )
230
 
231
- warning_md = gr.Markdown(
232
- visible=False
233
- )
 
234
 
235
- gr.HTML("</div>")
236
 
237
 
238
- # -------------------------
239
  # Actions
240
- # -------------------------
241
-
242
  generate_btn.click(
243
  fn=tts_interface,
244
  inputs=[
@@ -254,13 +206,10 @@ async def create_demo():
254
  )
255
 
256
 
257
- # -------------------------
258
  # Footer
259
- # -------------------------
260
-
261
  gr.HTML("""
262
  <div class="footer">
263
- © 2026 · SPJIMR AI Systems Lab · Experimental Research Platform
264
  </div>
265
  """)
266
 
@@ -280,7 +229,10 @@ async def main():
280
  default_concurrency_limit=50
281
  )
282
 
283
- demo.launch()
 
 
 
284
 
285
 
286
  if __name__ == "__main__":
 
28
  if not voice:
29
  return None, "Please select a voice."
30
 
31
+ voice_short = voice.split(" - ")[0]
32
 
33
  rate_str = f"{rate:+d}%"
34
  pitch_str = f"{pitch:+d}Hz"
35
 
36
  communicate = edge_tts.Communicate(
37
  text,
38
+ voice_short,
39
  rate=rate_str,
40
  pitch=pitch_str,
41
  )
42
 
43
  with tempfile.NamedTemporaryFile(
44
+ delete=False,
45
+ suffix=".mp3",
46
  ) as tmp:
47
  path = tmp.name
48
  await communicate.save(path)
 
63
 
64
 
65
  # -----------------------------
66
+ # Theme + CSS
67
  # -----------------------------
68
 
69
  SPJIMR_THEME = gr.themes.Base(
 
73
  font=["Inter", "sans-serif"],
74
  )
75
 
 
76
  CUSTOM_CSS = """
77
  body {
78
  background: #FAF8F6 !important;
 
84
  border-radius: 12px;
85
  color: white;
86
  text-align: center;
87
+ margin-bottom: 20px;
 
 
 
 
 
 
 
 
 
88
  }
89
 
90
  .card {
 
98
  .section-title {
99
  color: #7A1E2D;
100
  font-weight: 600;
 
101
  }
102
 
103
  .footer {
 
117
 
118
  voices = await get_voices()
119
 
120
+ with gr.Blocks(analytics_enabled=False) as demo:
 
 
 
 
121
 
 
122
  # Header
 
 
123
  gr.HTML("""
124
  <div id="header">
125
  <h1>🎙️ SPJIMR AI Voice Studio</h1>
126
+ <p>Professional Text-to-Speech Platform</p>
127
  </div>
128
  """)
129
 
130
+ # Main Layout
 
 
 
 
 
131
  with gr.Row():
132
 
133
+ # Input
134
  with gr.Column(scale=5):
135
 
136
+ gr.Markdown(
137
+ "### 📝 Input",
138
+ elem_classes="section-title",
139
+ )
 
 
 
 
 
 
 
 
140
 
141
+ text_input = gr.Textbox(
142
+ label="Text Script",
143
+ lines=7,
144
+ placeholder="Enter lecture notes, podcast scripts, or narration...",
145
+ )
146
 
147
+ voice_dropdown = gr.Dropdown(
148
+ choices=[""] + list(voices.keys()),
149
+ label="Voice Selection",
150
+ value="",
151
+ )
152
 
153
 
154
+ # Controls
155
  with gr.Column(scale=4):
156
 
157
+ gr.Markdown(
158
+ "### 🎛️ Controls",
159
+ elem_classes="section-title",
160
+ )
161
 
162
+ rate_slider = gr.Slider(
163
+ -50, 50, 0, step=1,
164
+ label="Speech Rate (%)"
165
+ )
166
 
167
+ pitch_slider = gr.Slider(
168
+ -20, 20, 0, step=1,
169
+ label="Pitch (Hz)"
170
+ )
 
 
 
171
 
172
+ generate_btn = gr.Button(
173
+ "Generate Audio",
174
+ variant="primary",
175
+ size="lg",
176
+ )
 
 
177
 
 
 
 
 
 
178
 
179
+ # Output
180
+ gr.Markdown(
181
+ "### 🔊 Output",
182
+ elem_classes="section-title",
183
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
184
 
185
+ audio_output = gr.Audio(
186
+ label="Generated Speech",
187
+ type="filepath",
188
+ )
189
 
190
+ warning_md = gr.Markdown(visible=False)
191
 
192
 
 
193
  # Actions
 
 
194
  generate_btn.click(
195
  fn=tts_interface,
196
  inputs=[
 
206
  )
207
 
208
 
 
209
  # Footer
 
 
210
  gr.HTML("""
211
  <div class="footer">
212
+ © 2026 · SPJIMR AI Systems Lab · Research Platform
213
  </div>
214
  """)
215
 
 
229
  default_concurrency_limit=50
230
  )
231
 
232
+ demo.launch(
233
+ theme=SPJIMR_THEME,
234
+ css=CUSTOM_CSS,
235
+ )
236
 
237
 
238
  if __name__ == "__main__":