HAMMALE commited on
Commit
c0f5b55
·
verified ·
1 Parent(s): c6694be

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +183 -69
app.py CHANGED
@@ -1,4 +1,3 @@
1
-
2
  import torch
3
  import soundfile as sf
4
  import os
@@ -82,116 +81,228 @@ def synthesize_speech(text, voice_type="male", speed=1.0):
82
  # Gradio imports need to be added
83
  import gradio as gr
84
 
85
- # Custom CSS for better design
86
  custom_css = """
 
 
 
 
 
 
 
 
87
  .gradio-container {
88
- font-family: 'Poppins', 'Arial', sans-serif;
89
- max-width: 750px;
90
- margin: auto;
 
 
 
 
 
 
91
  }
92
 
93
  .main-header {
94
- background: linear-gradient(90deg, #c31432, #240b36);
95
  color: white;
96
- padding: 1.5em;
97
- border-radius: 10px;
98
  text-align: center;
99
- margin-bottom: 1em;
100
- box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
101
  }
102
 
103
  .main-header h1 {
104
- font-size: 2.2em;
105
- margin-bottom: 0.3em;
 
 
 
106
  }
107
 
108
  .main-header p {
109
- font-size: 1.1em;
 
110
  opacity: 0.9;
 
111
  }
112
 
113
- footer {
114
- text-align: center;
115
- margin-top: 2em;
116
- color: #555;
117
- font-size: 0.9em;
118
  }
119
 
120
- .flag-icon {
121
- width: 24px;
122
- height: 24px;
123
- vertical-align: middle;
124
- margin-right: 8px;
 
 
 
125
  }
126
 
127
- .example-header {
128
- font-weight: bold;
129
- color: #c31432;
130
- margin-top: 1em;
131
  }
132
 
133
  .info-box {
134
- background-color: #f9f9f9;
135
- border-left: 4px solid #c31432;
136
- padding: 1em;
137
- margin: 1em 0;
138
- border-radius: 5px;
 
 
 
 
 
 
 
 
 
 
 
139
  }
140
 
141
- .voice-selector {
 
 
 
 
 
142
  display: flex;
143
  justify-content: center;
144
- gap: 20px;
145
- margin: 10px 0;
146
  }
147
 
148
- .voice-option {
149
- border: 2px solid #ddd;
150
- border-radius: 10px;
151
- padding: 10px 15px;
152
- transition: all 0.3s ease;
153
  cursor: pointer;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
  }
155
 
156
- .voice-option.selected {
157
- border-color: #c31432;
158
- background-color: #fff5f5;
159
  }
160
 
161
- .slider-container {
162
- margin: 20px 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163
  }
164
  """
165
 
166
- # Create Gradio interface with improved design
167
  with gr.Blocks(css=custom_css) as demo:
168
  gr.HTML(
169
  """
170
  <div class="main-header">
171
- <h1>🇲🇦 Moroccan Darija Text-to-Speech 🎧</h1>
172
- <p>Convert Moroccan Arabic (Darija) text into natural-sounding speech</p>
173
  </div>
174
  """
175
  )
176
 
177
- with gr.Row():
178
- with gr.Column():
179
  gr.HTML(
180
  """
181
  <div class="info-box">
182
- <p>This model was fine-tuned on the DODa audio dataset to produce high-quality
183
- Darija speech from text input. You can adjust the voice and speed below.</p>
184
  </div>
185
  """
186
  )
187
 
188
  text_input = gr.Textbox(
189
  label="Enter Darija Text",
190
- placeholder="Kteb chi jomla b darija hna...",
191
- lines=3
 
192
  )
193
 
194
- with gr.Row():
195
  voice_type = gr.Radio(
196
  ["male", "female"],
197
  label="Voice Type",
@@ -203,42 +314,45 @@ with gr.Blocks(css=custom_css) as demo:
203
  maximum=2.0,
204
  value=1.0,
205
  step=0.1,
206
- label="Speech Speed"
 
207
  )
208
 
209
- generate_btn = gr.Button("Generate Speech", variant="primary")
210
 
211
  gr.HTML(
212
  """
213
- <div class="example-header">Example phrases:</div>
214
  <ul>
215
  <li>"Ana Nadi Bezzaaf hhh"</li>
216
- <li>"Lyoum ajwaa zwina bezzaf."</li>
217
- <li>"lmaghrib ahssan blad fi l3alam "</li>
 
218
  </ul>
219
  """
220
  )
221
 
222
- with gr.Column():
223
- audio_output = gr.Audio(label="Generated Speech")
224
  error_output = gr.Textbox(label="Error (if any)", visible=False)
225
 
226
  gr.Examples(
227
  examples=[
228
- ["Ana Nadi Bezzaaf hhh", "male", 1.0],
229
- ["Lyoum ajwaa zwina bezzaf.", "female", 1.0],
230
- ["lmaghrib ahssan blad fi l3alam", "male", 1.0],
231
- ["Filistine hora mina lbar ila lbahr", "female", 0.8],
232
  ],
233
  inputs=[text_input, voice_type, speed],
234
  outputs=[audio_output, error_output],
235
- fn=synthesize_speech
 
236
  )
237
 
238
  gr.HTML(
239
  """
240
  <footer>
241
- <p>Developed by HAMMALE | Powered by Microsoft SpeechT5 | Data: DODa</p>
242
  </footer>
243
  """
244
  )
@@ -252,4 +366,4 @@ with gr.Blocks(css=custom_css) as demo:
252
 
253
  # Launch the demo
254
  if __name__ == "__main__":
255
- demo.launch()
 
 
1
  import torch
2
  import soundfile as sf
3
  import os
 
81
  # Gradio imports need to be added
82
  import gradio as gr
83
 
84
+ # Custom CSS for a full-screen, modern design
85
  custom_css = """
86
+ body, html {
87
+ margin: 0;
88
+ padding: 0;
89
+ height: 100%;
90
+ width: 100%;
91
+ overflow-x: hidden;
92
+ }
93
+
94
  .gradio-container {
95
+ font-family: 'Montserrat', 'Arial', sans-serif !important;
96
+ height: 100vh;
97
+ width: 100vw;
98
+ background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
99
+ display: flex;
100
+ flex-direction: column;
101
+ padding: 0;
102
+ margin: 0;
103
+ overflow-y: auto;
104
  }
105
 
106
  .main-header {
107
+ background: linear-gradient(90deg, #d32f2f, #1976d2);
108
  color: white;
109
+ padding: 2em;
 
110
  text-align: center;
111
+ box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
112
+ border-bottom: 4px solid #ffffff33;
113
  }
114
 
115
  .main-header h1 {
116
+ font-size: 2.8em;
117
+ margin: 0;
118
+ font-weight: 700;
119
+ letter-spacing: 1px;
120
+ text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
121
  }
122
 
123
  .main-header p {
124
+ font-size: 1.2em;
125
+ margin: 0.5em 0 0;
126
  opacity: 0.9;
127
+ font-weight: 300;
128
  }
129
 
130
+ .container {
131
+ max-width: 1200px;
132
+ margin: 2em auto;
133
+ padding: 0 1em;
134
+ flex: 1;
135
  }
136
 
137
+ .row {
138
+ display: flex;
139
+ gap: 2em;
140
+ background: white;
141
+ border-radius: 15px;
142
+ padding: 2em;
143
+ box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
144
+ margin-bottom: 2em;
145
  }
146
 
147
+ .column {
148
+ flex: 1;
149
+ padding: 1em;
 
150
  }
151
 
152
  .info-box {
153
+ background: #fef6f6;
154
+ border-left: 5px solid #d32f2f;
155
+ padding: 1.5em;
156
+ border-radius: 8px;
157
+ margin-bottom: 1.5em;
158
+ font-size: 1em;
159
+ line-height: 1.6;
160
+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
161
+ }
162
+
163
+ .textbox textarea {
164
+ border: 2px solid #e0e0e0 !important;
165
+ border-radius: 10px !important;
166
+ padding: 1em !important;
167
+ font-size: 1.1em !important;
168
+ transition: border-color 0.3s ease !important;
169
  }
170
 
171
+ .textbox textarea:focus {
172
+ border-color: #d32f2f !important;
173
+ box-shadow: 0 0 8px rgba(211, 47, 47, 0.2) !important;
174
+ }
175
+
176
+ .radio {
177
  display: flex;
178
  justify-content: center;
179
+ gap: 1.5em;
180
+ margin: 1em 0;
181
  }
182
 
183
+ .radio label {
184
+ background: #f5f5f5;
185
+ padding: 0.8em 1.5em;
186
+ border-radius: 25px;
187
+ border: 2px solid #e0e0e0;
188
  cursor: pointer;
189
+ transition: all 0.3s ease;
190
+ }
191
+
192
+ .radio input:checked + label {
193
+ background: #d32f2f;
194
+ color: white;
195
+ border-color: #d32f2f;
196
+ box-shadow: 0 4px 8px rgba(211, 47, 47, 0.2);
197
+ }
198
+
199
+ .slider {
200
+ margin: 1.5em 0;
201
+ }
202
+
203
+ .slider input {
204
+ accent-color: #d32f2f !important;
205
+ }
206
+
207
+ .button {
208
+ background: linear-gradient(90deg, #d32f2f, #1976d2) !important;
209
+ color: white !important;
210
+ padding: 1em 2em !important;
211
+ border-radius: 25px !important;
212
+ border: none !important;
213
+ font-size: 1.1em !important;
214
+ font-weight: 600 !important;
215
+ transition: transform 0.2s ease, box-shadow 0.3s ease !important;
216
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15) !important;
217
+ }
218
+
219
+ .button:hover {
220
+ transform: translateY(-2px) !important;
221
+ box-shadow: 0 6px 12px rgba(0, 0, 0, 0.25) !important;
222
  }
223
 
224
+ .audio {
225
+ margin-top: 1em;
 
226
  }
227
 
228
+ .audio audio {
229
+ width: 100%;
230
+ border-radius: 10px;
231
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
232
+ }
233
+
234
+ .example-header {
235
+ font-weight: 600;
236
+ color: #d32f2f;
237
+ margin: 1.5em 0 0.5em;
238
+ font-size: 1.2em;
239
+ }
240
+
241
+ ul {
242
+ padding-left: 1.5em;
243
+ color: #333;
244
+ }
245
+
246
+ li {
247
+ margin: 0.5em 0;
248
+ font-size: 1em;
249
+ }
250
+
251
+ .examples {
252
+ margin-top: 1.5em;
253
+ padding: 1em;
254
+ background: #f9f9f9;
255
+ border-radius: 10px;
256
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.05);
257
+ }
258
+
259
+ footer {
260
+ text-align: center;
261
+ padding: 1.5em;
262
+ background: #ffffff;
263
+ color: #666;
264
+ font-size: 0.95em;
265
+ border-top: 1px solid #e0e0e0;
266
+ margin-top: auto;
267
+ }
268
+
269
+ .flag-icon {
270
+ width: 30px;
271
+ height: 30px;
272
+ vertical-align: middle;
273
+ margin-right: 10px;
274
  }
275
  """
276
 
277
+ # Create Gradio interface with enhanced design
278
  with gr.Blocks(css=custom_css) as demo:
279
  gr.HTML(
280
  """
281
  <div class="main-header">
282
+ <h1>🇲🇦 Moroccan Darija Text-to-Speech 🎙️</h1>
283
+ <p>Transform your Darija text into lifelike speech with ease</p>
284
  </div>
285
  """
286
  )
287
 
288
+ with gr.Row(elem_classes="row"):
289
+ with gr.Column(elem_classes="column"):
290
  gr.HTML(
291
  """
292
  <div class="info-box">
293
+ <p>Experience high-quality Darija speech synthesis powered by the SpeechT5 model, fine-tuned on the DODa audio dataset. Customize the voice and speed to suit your needs.</p>
 
294
  </div>
295
  """
296
  )
297
 
298
  text_input = gr.Textbox(
299
  label="Enter Darija Text",
300
+ placeholder="Kteb chi jomla b darija hna, bhal 'Salam, kifach nta?'...",
301
+ lines=3,
302
+ elem_classes="textbox"
303
  )
304
 
305
+ with gr.Row(elem_classes="radio"):
306
  voice_type = gr.Radio(
307
  ["male", "female"],
308
  label="Voice Type",
 
314
  maximum=2.0,
315
  value=1.0,
316
  step=0.1,
317
+ label="Speech Speed",
318
+ elem_classes="slider"
319
  )
320
 
321
+ generate_btn = gr.Button("Generate Speech", variant="primary", elem_classes="button")
322
 
323
  gr.HTML(
324
  """
325
+ <div class="example-header">Try These Phrases:</div>
326
  <ul>
327
  <li>"Ana Nadi Bezzaaf hhh"</li>
328
+ <li>"Lyoum ajwaa zwina bezzaaf."</li>
329
+ <li>"Lmaghrib ahssan blad fi l3alam"</li>
330
+ <li>"Chukran bzzaf 3la lmosanada!"</li>
331
  </ul>
332
  """
333
  )
334
 
335
+ with gr.Column(elem_classes="column"):
336
+ audio_output = gr.Audio(label="Generated Speech", elem_classes="audio")
337
  error_output = gr.Textbox(label="Error (if any)", visible=False)
338
 
339
  gr.Examples(
340
  examples=[
341
+ ["Filistine horaa mina lbarri ila lbarri", "male", 0.8],
342
+ ["Lyoum ajwaa zwina bezzaaf.", "female", 1.0],
343
+ ["Lmaghrib ahssan blad fi l3alam", "male", 1.0],
344
+
345
  ],
346
  inputs=[text_input, voice_type, speed],
347
  outputs=[audio_output, error_output],
348
+ fn=synthesize_speech,
349
+ elem_classes="examples"
350
  )
351
 
352
  gr.HTML(
353
  """
354
  <footer>
355
+ <p>Developed by HAMMALE | Data: DODa Audio Dataset</p>
356
  </footer>
357
  """
358
  )
 
366
 
367
  # Launch the demo
368
  if __name__ == "__main__":
369
+ demo.launch()