youngtsai commited on
Commit
c7b2188
·
1 Parent(s): 79575ff
Files changed (1) hide show
  1. app.py +4 -3
app.py CHANGED
@@ -19,11 +19,12 @@ def generate_dialogue(rounds: int, method: str) -> list:
19
  dialogue.append({"role": "A" if i % 2 == 0 else "B", "text": ""})
20
  return dialogue
21
 
22
- # 3. 修改 Gradio 函數來返回音頻
23
  def generate_dialogue_with_audio(rounds: int, method: str):
24
  dialogue = generate_dialogue(rounds, method)
25
  audio_path = dialogue_to_audio(dialogue)
26
- return audio_path, dialogue
 
27
 
28
  # 4. 創建 Gradio 界面並啟動
29
  def main_interface():
@@ -35,7 +36,7 @@ def main_interface():
35
  ],
36
  outputs=[
37
  gr.components.Audio(type="filepath", label="對話朗讀"),
38
- gr.components.JSON(label="生成的對話")
39
  ]
40
  )
41
  interface.launch()
 
19
  dialogue.append({"role": "A" if i % 2 == 0 else "B", "text": ""})
20
  return dialogue
21
 
22
+ # 3. 修改 Gradio 函數來返回音頻和格式化的對話文本
23
  def generate_dialogue_with_audio(rounds: int, method: str):
24
  dialogue = generate_dialogue(rounds, method)
25
  audio_path = dialogue_to_audio(dialogue)
26
+ formatted_text = "\n".join([f"{item['role']}: {item['text']}" for item in dialogue])
27
+ return audio_path, formatted_text
28
 
29
  # 4. 創建 Gradio 界面並啟動
30
  def main_interface():
 
36
  ],
37
  outputs=[
38
  gr.components.Audio(type="filepath", label="對話朗讀"),
39
+ gr.components.Textbox(label="生成的對話")
40
  ]
41
  )
42
  interface.launch()