Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -304,10 +304,11 @@ def chat_response(message, history):
|
|
| 304 |
context = paper_mgr.search(message)
|
| 305 |
response = llm.chat(message, context)
|
| 306 |
|
| 307 |
-
#
|
| 308 |
-
history.
|
| 309 |
-
|
| 310 |
-
|
|
|
|
| 311 |
|
| 312 |
def voice_chat(audio_path, history):
|
| 313 |
"""Voice chat"""
|
|
@@ -328,33 +329,12 @@ def voice_chat(audio_path, history):
|
|
| 328 |
|
| 329 |
display_msg = f"🎤 You said: {text}\n\n🤖 Answer: {response}"
|
| 330 |
|
| 331 |
-
#
|
| 332 |
-
history.
|
| 333 |
-
|
|
|
|
| 334 |
|
| 335 |
-
return display_msg,
|
| 336 |
-
|
| 337 |
-
def voice_chat(audio_path, history):
|
| 338 |
-
"""Voice chat"""
|
| 339 |
-
if not audio_path:
|
| 340 |
-
return "No audio recorded", history
|
| 341 |
-
|
| 342 |
-
text = voice.transcribe(audio_path)
|
| 343 |
-
if text.startswith("Error"):
|
| 344 |
-
return text, history
|
| 345 |
-
|
| 346 |
-
print(f"🎤 Transcribed: '{text}'")
|
| 347 |
-
|
| 348 |
-
if not paper_mgr.index:
|
| 349 |
-
return "Load a paper first", history
|
| 350 |
-
|
| 351 |
-
context = paper_mgr.search(text.strip(), k=3)
|
| 352 |
-
response = llm.chat(text.strip(), context)
|
| 353 |
-
|
| 354 |
-
display_msg = f"🎤 You said: {text}\n\n🤖 Answer: {response}"
|
| 355 |
-
history = history + [[text, response]]
|
| 356 |
-
|
| 357 |
-
return display_msg, history
|
| 358 |
|
| 359 |
# ============================================================================
|
| 360 |
# BUILD UI
|
|
|
|
| 304 |
context = paper_mgr.search(message)
|
| 305 |
response = llm.chat(message, context)
|
| 306 |
|
| 307 |
+
# Create new history list to avoid reference issues
|
| 308 |
+
new_history = history.copy() if history else []
|
| 309 |
+
new_history.append({"role": "user", "content": message})
|
| 310 |
+
new_history.append({"role": "assistant", "content": response})
|
| 311 |
+
return "", new_history
|
| 312 |
|
| 313 |
def voice_chat(audio_path, history):
|
| 314 |
"""Voice chat"""
|
|
|
|
| 329 |
|
| 330 |
display_msg = f"🎤 You said: {text}\n\n🤖 Answer: {response}"
|
| 331 |
|
| 332 |
+
# Create new history list to avoid reference issues
|
| 333 |
+
new_history = history.copy() if history else []
|
| 334 |
+
new_history.append({"role": "user", "content": text})
|
| 335 |
+
new_history.append({"role": "assistant", "content": response})
|
| 336 |
|
| 337 |
+
return display_msg, new_history
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 338 |
|
| 339 |
# ============================================================================
|
| 340 |
# BUILD UI
|