rahul7star commited on
Commit
3067843
·
verified ·
1 Parent(s): 15a36ef

Update app_qwen_tts.py

Browse files
Files changed (1) hide show
  1. app_qwen_tts.py +18 -4
app_qwen_tts.py CHANGED
@@ -126,17 +126,31 @@ def chat(user_message, history, language_id, mode, exaggeration, temperature, cf
126
  if not user_message.strip():
127
  return "", history
128
  try:
 
129
  answer_text = answer_question(user_message)
 
 
130
  audio_src = tts_via_api(answer_text, language_id, mode, exaggeration, temperature, cfg_weight)
 
 
 
 
 
 
 
 
 
 
 
131
  except Exception as e:
132
  print(e)
133
- answer_text = "⚠️ Error generating answer or audio."
134
- audio_src = None
135
 
136
- # Return as tuple for 'tuples' type: (user_message, [text, audio])
137
- history.append((user_message, [answer_text, audio_src]))
138
  return "", history
139
 
 
140
  def reset_chat():
141
  return []
142
 
 
126
  if not user_message.strip():
127
  return "", history
128
  try:
129
+ # 1️⃣ Get Qwen answer
130
  answer_text = answer_question(user_message)
131
+
132
+ # 2️⃣ Get TTS from API
133
  audio_src = tts_via_api(answer_text, language_id, mode, exaggeration, temperature, cfg_weight)
134
+
135
+ # 3️⃣ Format bot message nicely with spacing
136
+ if audio_src:
137
+ # Use a small HTML wrapper for spacing
138
+ bot_content = [
139
+ f"<div style='margin-bottom:8px;'>{answer_text}</div>", # text with margin
140
+ audio_src # playable audio below
141
+ ]
142
+ else:
143
+ bot_content = [answer_text]
144
+
145
  except Exception as e:
146
  print(e)
147
+ bot_content = ["⚠️ Error generating answer or audio."]
 
148
 
149
+ # 4️⃣ Append as tuple: (user_message, bot_content)
150
+ history.append((user_message, bot_content))
151
  return "", history
152
 
153
+
154
  def reset_chat():
155
  return []
156