NariLabs commited on
Commit
ba7fe05
·
verified ·
1 Parent(s): 06ec647

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +28 -17
app.py CHANGED
@@ -36,18 +36,26 @@ def _concat_script(turn_count: int, turn_values: List[str]) -> str:
36
  return "\n".join(lines)
37
 
38
 
39
- EXAMPLES: dict[str, List[str]] = {
40
- "Intro": [
41
- "Hello Dia2 fans! Today we're unveiling the new open TTS model.",
42
- "Sounds exciting. Can you show a sample right now?",
43
- "Absolutely. (laughs) Just press generate.",
44
- ],
45
- "Customer Support": [
46
- "Thanks for calling. How can I help you today?",
47
- "My parcel never arrived and it's been two weeks.",
48
- "I'm sorry about that. Let me check your tracking number.",
49
- "Appreciate it. I really need that package soon.",
50
- ],
 
 
 
 
 
 
 
 
51
  }
52
 
53
 
@@ -68,15 +76,18 @@ def _remove_turn(count: int):
68
  def _load_example(name: str, count: int):
69
  data = EXAMPLES.get(name)
70
  if not data:
71
- return (count, *_apply_turn_visibility(count))
72
- new_count = min(len(data), MAX_TURNS)
 
 
 
73
  updates: List[gr.Update] = []
74
  for idx in range(MAX_TURNS):
75
  if idx < new_count:
76
- updates.append(gr.update(value=data[idx], visible=True))
77
  else:
78
  updates.append(gr.update(value="", visible=idx < INITIAL_TURNS))
79
- return (new_count, *updates)
80
 
81
 
82
  def _prepare_prefix(file_path: str | None) -> str | None:
@@ -223,7 +234,7 @@ Compose dialogue, attach optional voice prompts, and generate audio (CUDA graphs
223
  example_dropdown.change(
224
  lambda name, c: _load_example(name, c),
225
  inputs=[example_dropdown, turn_state],
226
- outputs=[turn_state, *controls],
227
  )
228
 
229
  generate_btn.click(
 
36
  return "\n".join(lines)
37
 
38
 
39
+ EXAMPLES: dict[str, dict[str, List[str] | str | None]] = {
40
+ "Intro": {
41
+ "turns": [
42
+ "Hello Dia2 fans! Today we're unveiling the new open TTS model.",
43
+ "Sounds exciting. Can you show a sample right now?",
44
+ "Absolutely. (laughs) Just press generate.",
45
+ ],
46
+ "voice_s1": "example_prefix1.wav",
47
+ "voice_s2": "example_prefix2.wav",
48
+ },
49
+ "Customer Support": {
50
+ "turns": [
51
+ "Thanks for calling. How can I help you today?",
52
+ "My parcel never arrived and it's been two weeks.",
53
+ "I'm sorry about that. Let me check your tracking number.",
54
+ "Appreciate it. I really need that package soon.",
55
+ ],
56
+ "voice_s1": "example_prefix1.wav",
57
+ "voice_s2": "example_prefix2.wav",
58
+ },
59
  }
60
 
61
 
 
76
  def _load_example(name: str, count: int):
77
  data = EXAMPLES.get(name)
78
  if not data:
79
+ return (count, *_apply_turn_visibility(count), None, None)
80
+ turns = data.get("turns", [])
81
+ voice_s1_path = data.get("voice_s1")
82
+ voice_s2_path = data.get("voice_s2")
83
+ new_count = min(len(turns), MAX_TURNS)
84
  updates: List[gr.Update] = []
85
  for idx in range(MAX_TURNS):
86
  if idx < new_count:
87
+ updates.append(gr.update(value=turns[idx], visible=True))
88
  else:
89
  updates.append(gr.update(value="", visible=idx < INITIAL_TURNS))
90
+ return (new_count, *updates, voice_s1_path, voice_s2_path)
91
 
92
 
93
  def _prepare_prefix(file_path: str | None) -> str | None:
 
234
  example_dropdown.change(
235
  lambda name, c: _load_example(name, c),
236
  inputs=[example_dropdown, turn_state],
237
+ outputs=[turn_state, *controls, voice_s1, voice_s2],
238
  )
239
 
240
  generate_btn.click(