youngtsai commited on
Commit
f2bc1ef
1 Parent(s): 4060a57

chatbot_dialogue

Browse files
Files changed (1) hide show
  1. app.py +11 -2
app.py CHANGED
@@ -11,8 +11,16 @@ def generate_dialogue(rounds, method, role1, role2):
11
 
12
  def main_function(rounds: int, method: str, role1: str, role2: str):
13
  structured_dialogue = generate_dialogue(rounds, method, role1, role2)
14
- chatbot_dialogue = [(item["role"], item["content"]) for item in structured_dialogue]
15
- print(chatbot_dialogue)
 
 
 
 
 
 
 
 
16
  audio_path = dialogue_to_audio(structured_dialogue)
17
  json_output = json.dumps({"dialogue": structured_dialogue}, ensure_ascii=False, indent=4)
18
 
@@ -23,6 +31,7 @@ def main_function(rounds: int, method: str, role1: str, role2: str):
23
 
24
  return chatbot_dialogue, audio_path, file_name
25
 
 
26
  def dialogue_to_audio(dialogue):
27
  text = " ".join([f"{item['role']}: {item['content']}" for item in dialogue])
28
  tts = gTTS(text=text, lang='zh-tw')
 
11
 
12
  def main_function(rounds: int, method: str, role1: str, role2: str):
13
  structured_dialogue = generate_dialogue(rounds, method, role1, role2)
14
+
15
+ # Convert structured dialogue for Chatbot component to show "role1: content1" and "role2: content2" side by side
16
+ chatbot_dialogue = []
17
+ for i in range(0, len(structured_dialogue), 2): # We iterate with a step of 2 to take pairs
18
+ # Get the content for the two roles in the pair
19
+ role1_content = f"{structured_dialogue[i]['role']}: {structured_dialogue[i]['content']}"
20
+ role2_content = f"{structured_dialogue[i+1]['role']}: {structured_dialogue[i+1]['content']}" if i+1 < len(structured_dialogue) else ""
21
+
22
+ chatbot_dialogue.append((role1_content, role2_content))
23
+
24
  audio_path = dialogue_to_audio(structured_dialogue)
25
  json_output = json.dumps({"dialogue": structured_dialogue}, ensure_ascii=False, indent=4)
26
 
 
31
 
32
  return chatbot_dialogue, audio_path, file_name
33
 
34
+
35
  def dialogue_to_audio(dialogue):
36
  text = " ".join([f"{item['role']}: {item['content']}" for item in dialogue])
37
  tts = gTTS(text=text, lang='zh-tw')