Spaces:
Running
Running
Update app_qwen_tts.py
Browse files- app_qwen_tts.py +18 -13
app_qwen_tts.py
CHANGED
|
@@ -130,6 +130,9 @@ def tts_via_api(text: str, language_id="en", mode="Speak 🗣️", exaggeration=
|
|
| 130 |
print(f"TTS API error: {e}")
|
| 131 |
return None
|
| 132 |
|
|
|
|
|
|
|
|
|
|
| 133 |
# =========================================================
|
| 134 |
# Chat function
|
| 135 |
# =========================================================
|
|
@@ -138,24 +141,25 @@ def chat(user_message, history):
|
|
| 138 |
return "", history
|
| 139 |
|
| 140 |
try:
|
| 141 |
-
# 1️⃣ Generate answer
|
| 142 |
answer_text = answer_question(user_message)
|
| 143 |
|
| 144 |
# 2️⃣ Generate audio
|
| 145 |
audio_data = tts_via_api(answer_text)
|
| 146 |
|
| 147 |
-
# 3️⃣ Append
|
| 148 |
-
history.append({
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
|
|
|
| 159 |
except Exception as e:
|
| 160 |
print(e)
|
| 161 |
history.append({
|
|
@@ -165,6 +169,7 @@ def chat(user_message, history):
|
|
| 165 |
|
| 166 |
return "", history
|
| 167 |
|
|
|
|
| 168 |
def reset_chat():
|
| 169 |
return []
|
| 170 |
|
|
|
|
| 130 |
print(f"TTS API error: {e}")
|
| 131 |
return None
|
| 132 |
|
| 133 |
+
# =========================================================
|
| 134 |
+
# Chat function
|
| 135 |
+
# =========================================================
|
| 136 |
# =========================================================
|
| 137 |
# Chat function
|
| 138 |
# =========================================================
|
|
|
|
| 141 |
return "", history
|
| 142 |
|
| 143 |
try:
|
| 144 |
+
# 1️⃣ Generate text answer
|
| 145 |
answer_text = answer_question(user_message)
|
| 146 |
|
| 147 |
# 2️⃣ Generate audio
|
| 148 |
audio_data = tts_via_api(answer_text)
|
| 149 |
|
| 150 |
+
# 3️⃣ Append messages in 'messages' format
|
| 151 |
+
history.append({"role": "user", "content": user_message})
|
| 152 |
+
if audio_data:
|
| 153 |
+
history.append({
|
| 154 |
+
"role": "assistant",
|
| 155 |
+
"content": [f"**Bot:** {answer_text}", audio_data]
|
| 156 |
+
})
|
| 157 |
+
else:
|
| 158 |
+
history.append({
|
| 159 |
+
"role": "assistant",
|
| 160 |
+
"content": f"**Bot:** {answer_text}"
|
| 161 |
+
})
|
| 162 |
+
|
| 163 |
except Exception as e:
|
| 164 |
print(e)
|
| 165 |
history.append({
|
|
|
|
| 169 |
|
| 170 |
return "", history
|
| 171 |
|
| 172 |
+
|
| 173 |
def reset_chat():
|
| 174 |
return []
|
| 175 |
|