PaulineDV commited on
Commit
12672c8
·
1 Parent(s): d35d040

context and context score added

Browse files
Files changed (1) hide show
  1. app.py +74 -25
app.py CHANGED
@@ -29,6 +29,23 @@ SENTENCES = [
29
  "Les systèmes vocaux progressent rapidement"
30
  ]
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  # ============================
33
  # CONFIGURATION
34
  # ============================
@@ -77,7 +94,9 @@ f5tts = F5TTS()
77
 
78
  print("F5-TTS loaded")
79
 
80
- def generate_audio(model_name, sentence):
 
 
81
 
82
  if model_name == "OmniVoice":
83
  return generate_omnivoice(sentence)
@@ -146,8 +165,9 @@ def submit_annotation_hf(
146
  tts_experience,
147
  device_type,
148
  selected_model,
149
- sentence,
150
- score
 
151
  ):
152
  annotation = {
153
  "user_id": user_id,
@@ -158,9 +178,10 @@ def submit_annotation_hf(
158
  "device_type": device_type,
159
 
160
  "model_name": selected_model,
161
- "sentence": sentence,
162
 
163
  "score": score,
 
164
  "timestamp": datetime.now(UTC).isoformat()
165
  }
166
 
@@ -168,17 +189,17 @@ def submit_annotation_hf(
168
  short_id = str(uuid.uuid4()) [:8]
169
 
170
  file_name = (
171
- f"OmniVoice_{user_id}_{timestamp}_{short_id}"
172
  )
173
 
174
- local_file = file_name
175
 
176
  with open(local_file, "w", encoding="utf-8") as f:
177
  json.dump(annotation, f, indent=2)
178
 
179
  api.upload_file(
180
  path_or_fileobj=local_file,
181
- path_in_repo=f"annotations/{file_name}.json",
182
  repo_id=HF_DATASET_NAME,
183
  repo_type="dataset"
184
  )
@@ -194,10 +215,12 @@ def submit_annotation(
194
  tts_experience,
195
  device_type,
196
  selected_model,
197
- sentence,
198
- score
 
199
  ):
200
-
 
201
  submit_annotation_hf(
202
  user_id,
203
  age_group,
@@ -206,11 +229,24 @@ def submit_annotation(
206
  tts_experience,
207
  device_type,
208
  selected_model,
209
- sentence,
210
- score
 
211
  )
212
 
213
- return f"Annotation saved for {sentence}."
 
 
 
 
 
 
 
 
 
 
 
 
214
 
215
  # ============================
216
  # SUBMIT BUTTON CONTROL
@@ -272,12 +308,12 @@ with gr.Blocks() as demo:
272
  with gr.Row():
273
  age_group = gr.Dropdown(
274
  choices=[
275
- "10-20",
276
- "20-30",
277
- "30-40",
278
- "40-50",
279
- "50-60",
280
- "60-70",
281
  "70+"
282
  ],
283
  label="Age Group"
@@ -309,10 +345,15 @@ with gr.Blocks() as demo:
309
  )
310
 
311
  with gr.Row():
312
- sentence_selector = gr.Dropdown(
313
- choices=SENTENCES,
314
- value=SENTENCES[0],
315
- label="Sentence to synthesize"
 
 
 
 
 
316
  )
317
 
318
  model_selector = gr.Dropdown(
@@ -321,6 +362,12 @@ with gr.Blocks() as demo:
321
  label = "Model"
322
  )
323
 
 
 
 
 
 
 
324
  generate_btn = gr.Button("Generate Audio")
325
 
326
  audio_player = gr.Audio(label="Generated audio")
@@ -329,13 +376,14 @@ with gr.Blocks() as demo:
329
  generate_audio,
330
  inputs=[
331
  model_selector,
332
- sentence_selector
333
  ],
334
  outputs=[audio_player, audio_played]
335
  )
336
 
337
  with gr.Row():
338
  score = gr.Dropdown(choices=["None","1", "2", "3", "4", "5"], value="None", label="MOS Score (1–5)")
 
339
  submit_btn = gr.Button("Submit Score", interactive=False)
340
 
341
  status = gr.Textbox(label="Status", interactive=False)
@@ -375,7 +423,8 @@ with gr.Blocks() as demo:
375
  native_language,
376
  tts_experience,
377
  device_type,
378
- sentence_selector,
 
379
  score
380
  ],
381
  outputs=status
 
29
  "Les systèmes vocaux progressent rapidement"
30
  ]
31
 
32
+ CONTEXTS = {
33
+ "Train station announcement":
34
+ "Le train 7891 à destination de Paris Nord, prévu à 14h35, partira voie 8.",
35
+
36
+ "Weather forecast":
37
+ "Demain, les températures atteindront 27 degrés avec un ciel dégagé.",
38
+
39
+ "Voice assistant":
40
+ "Je peux vous aider à trouver le restaurant le plus proche.",
41
+
42
+ "Audiobook":
43
+ "Le vieux château se dressait au sommet de la colline depuis plusieurs siècles.",
44
+
45
+ "Customer service":
46
+ "Votre demande a bien été prise en compte et sera traitée sous quarante-huit heures."
47
+ }
48
+
49
  # ============================
50
  # CONFIGURATION
51
  # ============================
 
94
 
95
  print("F5-TTS loaded")
96
 
97
+ def generate_audio(model_name, context):
98
+
99
+ sentence = CONTEXTS[context]
100
 
101
  if model_name == "OmniVoice":
102
  return generate_omnivoice(sentence)
 
165
  tts_experience,
166
  device_type,
167
  selected_model,
168
+ context,
169
+ score,
170
+ context_score
171
  ):
172
  annotation = {
173
  "user_id": user_id,
 
178
  "device_type": device_type,
179
 
180
  "model_name": selected_model,
181
+ "context": context,
182
 
183
  "score": score,
184
+ "context_score": context_score,
185
  "timestamp": datetime.now(UTC).isoformat()
186
  }
187
 
 
189
  short_id = str(uuid.uuid4()) [:8]
190
 
191
  file_name = (
192
+ f"{selected_model}_{user_id}_{timestamp}_{short_id}"
193
  )
194
 
195
+ local_file = f"{file_name}.json"
196
 
197
  with open(local_file, "w", encoding="utf-8") as f:
198
  json.dump(annotation, f, indent=2)
199
 
200
  api.upload_file(
201
  path_or_fileobj=local_file,
202
+ path_in_repo=f"annotations/{local_file}",
203
  repo_id=HF_DATASET_NAME,
204
  repo_type="dataset"
205
  )
 
215
  tts_experience,
216
  device_type,
217
  selected_model,
218
+ context,
219
+ score,
220
+ context_score
221
  ):
222
+ try:
223
+
224
  submit_annotation_hf(
225
  user_id,
226
  age_group,
 
229
  tts_experience,
230
  device_type,
231
  selected_model,
232
+ context,
233
+ score,
234
+ context_score
235
  )
236
 
237
+ return f"Annotation saved for {context}."
238
+
239
+ except Exception as e:
240
+ print("Submit error")
241
+ print(type(e).__name__)
242
+ print(e)
243
+
244
+ return f"ERROR: {e}"
245
+
246
+ def update_sentence(context):
247
+
248
+ return CONTEXTS[context]
249
+
250
 
251
  # ============================
252
  # SUBMIT BUTTON CONTROL
 
308
  with gr.Row():
309
  age_group = gr.Dropdown(
310
  choices=[
311
+ "10-19",
312
+ "20-29",
313
+ "30-39",
314
+ "40-49",
315
+ "50-59",
316
+ "60-69",
317
  "70+"
318
  ],
319
  label="Age Group"
 
345
  )
346
 
347
  with gr.Row():
348
+ context_selector = gr.Dropdown(
349
+ choices=list(CONTEXTS.keys()),
350
+ value="Train station announcement",
351
+ label="Context"
352
+ )
353
+
354
+ sentence_display = gr.Textbox(
355
+ label = "Sentence",
356
+ interactive = False
357
  )
358
 
359
  model_selector = gr.Dropdown(
 
362
  label = "Model"
363
  )
364
 
365
+ context_selector.change(
366
+ update_sentence,
367
+ inputs=context_selector,
368
+ outputs=sentence_display
369
+ )
370
+
371
  generate_btn = gr.Button("Generate Audio")
372
 
373
  audio_player = gr.Audio(label="Generated audio")
 
376
  generate_audio,
377
  inputs=[
378
  model_selector,
379
+ context_selector
380
  ],
381
  outputs=[audio_player, audio_played]
382
  )
383
 
384
  with gr.Row():
385
  score = gr.Dropdown(choices=["None","1", "2", "3", "4", "5"], value="None", label="MOS Score (1–5)")
386
+ score_context = gr.Dropdown(choices=["None","1", "2", "3", "4", "5"], value="None", label="Voice-context adequacy")
387
  submit_btn = gr.Button("Submit Score", interactive=False)
388
 
389
  status = gr.Textbox(label="Status", interactive=False)
 
423
  native_language,
424
  tts_experience,
425
  device_type,
426
+ model_selector,
427
+ context_selector,
428
  score
429
  ],
430
  outputs=status