rulerman commited on
Commit
a84101f
·
1 Parent(s): 94e894c

update example

Browse files
Files changed (3) hide show
  1. app.py +135 -0
  2. asset/reference_02_s1.wav +3 -0
  3. asset/reference_02_s2.wav +3 -0
app.py CHANGED
@@ -39,6 +39,66 @@ DEFAULT_ATTN_IMPLEMENTATION = "auto"
39
  DEFAULT_MAX_NEW_TOKENS = 2000
40
  MIN_SPEAKERS = 1
41
  MAX_SPEAKERS = 5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
 
43
 
44
  def resolve_attn_implementation(requested: str, device: torch.device, dtype: torch.dtype) -> str | None:
@@ -212,6 +272,59 @@ def update_speaker_panels(speaker_count: int):
212
  return [gr.update(visible=(idx < count)) for idx in range(MAX_SPEAKERS)]
213
 
214
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
215
  def _merge_consecutive_speaker_tags(text: str) -> str:
216
  segments = re.split(r"(?=\[S\d+\])", text)
217
  if not segments:
@@ -609,12 +722,34 @@ def build_demo(args: argparse.Namespace):
609
  output_audio = gr.Audio(label="Output Audio", type="numpy", elem_id="output_audio")
610
  gr.HTML("", elem_id="output_audio_spacer")
611
  status = gr.Textbox(label="Status", lines=4, interactive=False, elem_id="output_status")
 
 
 
 
 
 
 
 
 
 
612
 
613
  speaker_count.change(
614
  fn=update_speaker_panels,
615
  inputs=[speaker_count],
616
  outputs=speaker_panels,
617
  )
 
 
 
 
 
 
 
 
 
 
 
 
618
 
619
  run_btn.click(
620
  fn=run_inference,
 
39
  DEFAULT_MAX_NEW_TOKENS = 2000
40
  MIN_SPEAKERS = 1
41
  MAX_SPEAKERS = 5
42
+ PRESET_REF_AUDIO_S1 = "asset/reference_02_s1.wav"
43
+ PRESET_REF_AUDIO_S2 = "asset/reference_02_s2.wav"
44
+ PRESET_PROMPT_TEXT_S1 = (
45
+ "[S1] In short, we embarked on a mission to make America great again for all Americans."
46
+ )
47
+ PRESET_PROMPT_TEXT_S2 = (
48
+ "[S2] NVIDIA reinvented computing for the first time after 60 years. In fact, Erwin at IBM knows quite "
49
+ "well that the computer has largely been the same since the 60s."
50
+ )
51
+ PRESET_DIALOGUE_TEXT = (
52
+ "[S1] Listen, let's talk business. China. I'm hearing things.\n"
53
+ "People are saying they're catching up. Fast. What's the real scoop?\n"
54
+ "Their AI, is it a threat?\n"
55
+ "[S2] Well, the pace of innovation there is extraordinary, honestly.\n"
56
+ "They have the researchers, and they have the drive.\n"
57
+ "[S1] Extraordinary? I don't like that. I want us to be extraordinary.\n"
58
+ "Are they winning?\n"
59
+ "[S2] I wouldn't say winning, but their progress is very promising.\n"
60
+ "They are building massive clusters. They're very determined.\n"
61
+ "[S1] Promising. There it is. I hate that word.\n"
62
+ "When China is promising, it means we're losing.\n"
63
+ "It's a disaster, Jensen. A total disaster."
64
+ )
65
+ PRESET_EXAMPLES = [
66
+ {
67
+ "name": "Quick Start | reference_02_s1/s2",
68
+ "speaker_count": 2,
69
+ "s1_audio": PRESET_REF_AUDIO_S1,
70
+ "s1_prompt": PRESET_PROMPT_TEXT_S1,
71
+ "s2_audio": PRESET_REF_AUDIO_S2,
72
+ "s2_prompt": PRESET_PROMPT_TEXT_S2,
73
+ "dialogue_text": PRESET_DIALOGUE_TEXT,
74
+ }
75
+ ]
76
+ PRESET_DISPLAY_FIELDS = [
77
+ ("Speaker Count", "speaker_count"),
78
+ ("S1 Reference Audio (Optional)", "s1_audio"),
79
+ ("S1 Prompt Text (Required with reference audio)", "s1_prompt"),
80
+ ("S2 Reference Audio (Optional)", "s2_audio"),
81
+ ("S2 Prompt Text (Required with reference audio)", "s2_prompt"),
82
+ ("Dialogue Text", "dialogue_text"),
83
+ ]
84
+
85
+
86
+ def _build_preset_table_rows():
87
+ rows = []
88
+ row_to_preset = []
89
+ for preset_idx, preset in enumerate(PRESET_EXAMPLES):
90
+ for field_name, field_key in PRESET_DISPLAY_FIELDS:
91
+ value = str(preset.get(field_key, ""))
92
+ if field_key == "dialogue_text":
93
+ value = value.replace("\n", " ").strip()
94
+ if len(value) > 120:
95
+ value = value[:120] + " ..."
96
+ rows.append([field_name, value])
97
+ row_to_preset.append(preset_idx)
98
+ return rows, row_to_preset
99
+
100
+
101
+ PRESET_TABLE_ROWS, PRESET_TABLE_ROW_TO_PRESET = _build_preset_table_rows()
102
 
103
 
104
  def resolve_attn_implementation(requested: str, device: torch.device, dtype: torch.dtype) -> str | None:
 
272
  return [gr.update(visible=(idx < count)) for idx in range(MAX_SPEAKERS)]
273
 
274
 
275
+ def apply_preset_selection(evt: gr.SelectData):
276
+ if evt is None or evt.index is None:
277
+ return (
278
+ gr.update(),
279
+ gr.update(),
280
+ gr.update(),
281
+ gr.update(),
282
+ gr.update(),
283
+ gr.update(),
284
+ *[gr.update() for _ in range(MAX_SPEAKERS)],
285
+ )
286
+
287
+ if isinstance(evt.index, (tuple, list)):
288
+ row_idx = int(evt.index[0])
289
+ else:
290
+ row_idx = int(evt.index)
291
+
292
+ if row_idx < 0 or row_idx >= len(PRESET_TABLE_ROW_TO_PRESET):
293
+ return (
294
+ gr.update(),
295
+ gr.update(),
296
+ gr.update(),
297
+ gr.update(),
298
+ gr.update(),
299
+ gr.update(),
300
+ *[gr.update() for _ in range(MAX_SPEAKERS)],
301
+ )
302
+
303
+ preset_idx = PRESET_TABLE_ROW_TO_PRESET[row_idx]
304
+ if preset_idx < 0 or preset_idx >= len(PRESET_EXAMPLES):
305
+ return (
306
+ gr.update(),
307
+ gr.update(),
308
+ gr.update(),
309
+ gr.update(),
310
+ gr.update(),
311
+ gr.update(),
312
+ *[gr.update() for _ in range(MAX_SPEAKERS)],
313
+ )
314
+
315
+ preset = PRESET_EXAMPLES[preset_idx]
316
+ panel_updates = update_speaker_panels(int(preset["speaker_count"]))
317
+ return (
318
+ gr.update(value=int(preset["speaker_count"])),
319
+ gr.update(value=str(preset["s1_audio"])),
320
+ gr.update(value=str(preset["s1_prompt"])),
321
+ gr.update(value=str(preset["s2_audio"])),
322
+ gr.update(value=str(preset["s2_prompt"])),
323
+ gr.update(value=str(preset["dialogue_text"])),
324
+ *panel_updates,
325
+ )
326
+
327
+
328
  def _merge_consecutive_speaker_tags(text: str) -> str:
329
  segments = re.split(r"(?=\[S\d+\])", text)
330
  if not segments:
 
722
  output_audio = gr.Audio(label="Output Audio", type="numpy", elem_id="output_audio")
723
  gr.HTML("", elem_id="output_audio_spacer")
724
  status = gr.Textbox(label="Status", lines=4, interactive=False, elem_id="output_status")
725
+ preset_examples = gr.Dataframe(
726
+ headers=["Field", "Value (click any row to fill inputs)"],
727
+ value=PRESET_TABLE_ROWS,
728
+ datatype=["str", "str"],
729
+ row_count=(len(PRESET_TABLE_ROWS), "fixed"),
730
+ col_count=(2, "fixed"),
731
+ interactive=False,
732
+ wrap=True,
733
+ label="Preset Examples",
734
+ )
735
 
736
  speaker_count.change(
737
  fn=update_speaker_panels,
738
  inputs=[speaker_count],
739
  outputs=speaker_panels,
740
  )
741
+ preset_examples.select(
742
+ fn=apply_preset_selection,
743
+ outputs=[
744
+ speaker_count,
745
+ speaker_refs[0],
746
+ speaker_prompts[0],
747
+ speaker_refs[1],
748
+ speaker_prompts[1],
749
+ dialogue_text,
750
+ *speaker_panels,
751
+ ],
752
+ )
753
 
754
  run_btn.click(
755
  fn=run_inference,
asset/reference_02_s1.wav ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1816ab428334ba2de49dcb8b0a10e17eb1835f7f1f7bcda13504e88f46bed1e8
3
+ size 249284
asset/reference_02_s2.wav ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0a407b1cba86ee320849208f4de0a437a0cb6ab4dbc52a595d99fbffda98aa35
3
+ size 2268548