TDN-M commited on
Commit
ff02166
·
verified ·
1 Parent(s): 371fde7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -4
app.py CHANGED
@@ -68,17 +68,42 @@ def start_debate(topic, position_1, position_2):
68
  audio_links = [f"[Turn {i+1}]({file})" for i, file in enumerate(audio_files)]
69
  return f"The debate has started! {turn} begins.", history, audio_links
70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  # Hàm để chuyển lượt trong tranh luận
72
  def next_turn(topic, position_1, position_2, current_history):
73
  global turn, history, audio_files
74
  if not current_history:
75
- return "No ongoing debate. Please start a debate first.", [], []
76
 
77
  # Logic chuyển lượt
78
  if turn == "Miss AI Vietnam":
79
  turn = "Miss AI China"
80
  llm, position, who = MissAIChina, position_2, 'Miss AI China'
81
- voice = "en-AU-NatashaNeural" # Giọng nữ tiếng Anh Anh
82
  else:
83
  turn = "Miss AI Vietnam"
84
  llm, position, who = MissAIVietnam, position_1, "Miss AI Vietnam"
@@ -92,8 +117,8 @@ def next_turn(topic, position_1, position_2, current_history):
92
  output_file = asyncio.run(text_to_speech(response, voice))
93
  audio_files.append(output_file) # Thêm file audio vào danh sách
94
 
95
- # Tạo danh sách link audio
96
- audio_links = [f"[Turn {i+1}]({file})" for i, file in enumerate(audio_files)]
97
  return f"It's now {turn}'s turn.", history, audio_links
98
 
99
  # Giao diện Gradio
 
68
  audio_links = [f"[Turn {i+1}]({file})" for i, file in enumerate(audio_files)]
69
  return f"The debate has started! {turn} begins.", history, audio_links
70
 
71
+ # Hàm để bắt đầu tranh luận giữa Miss AI Vietnam và Miss AI China
72
+ def start_debate(topic, position_1, position_2):
73
+ global turn, history, audio_files
74
+ if not topic or not position_1 or not position_2:
75
+ return "Please provide the debate topic and positions for both participants.", [], ""
76
+
77
+ # Đảm bảo các vị trí là đối lập
78
+ if position_1 == position_2:
79
+ return "The positions of both participants must be opposite. Please adjust them.", [], ""
80
+
81
+ turn = "Miss AI Vietnam"
82
+ history = [] # Đặt lại lịch sử
83
+ audio_files = [] # Đặt lại danh sách file audio
84
+ initial_message = "Opening Statement"
85
+ response = generate_response(MissAIVietnam, position_1, 'Miss AI Vietnam', topic, initial_message)
86
+ history.append((initial_message, response))
87
+
88
+ # Chuyển văn bản thành âm thanh với giọng của Miss AI Vietnam
89
+ output_file = asyncio.run(text_to_speech(response, "en-US-JennyNeural")) # Giọng nữ tiếng Anh Mỹ
90
+ audio_files.append(output_file) # Thêm file audio vào danh sách
91
+
92
+ # Tạo chuỗi liên kết audio
93
+ audio_links = "\n".join([f"[Turn {i+1}]({file})" for i, file in enumerate(audio_files)])
94
+ return f"The debate has started! {turn} begins.", history, audio_links
95
+
96
  # Hàm để chuyển lượt trong tranh luận
97
  def next_turn(topic, position_1, position_2, current_history):
98
  global turn, history, audio_files
99
  if not current_history:
100
+ return "No ongoing debate. Please start a debate first.", [], ""
101
 
102
  # Logic chuyển lượt
103
  if turn == "Miss AI Vietnam":
104
  turn = "Miss AI China"
105
  llm, position, who = MissAIChina, position_2, 'Miss AI China'
106
+ voice = "en-GB-LibbyNeural" # Giọng nữ tiếng Anh Anh
107
  else:
108
  turn = "Miss AI Vietnam"
109
  llm, position, who = MissAIVietnam, position_1, "Miss AI Vietnam"
 
117
  output_file = asyncio.run(text_to_speech(response, voice))
118
  audio_files.append(output_file) # Thêm file audio vào danh sách
119
 
120
+ # Tạo chuỗi liên kết audio
121
+ audio_links = "\n".join([f"[Turn {i+1}]({file})" for i, file in enumerate(audio_files)])
122
  return f"It's now {turn}'s turn.", history, audio_links
123
 
124
  # Giao diện Gradio