commit
Browse files
app.py
CHANGED
|
@@ -59,57 +59,31 @@ def format_sources(src):
|
|
| 59 |
|
| 60 |
return "\n".join(out)
|
| 61 |
|
| 62 |
-
#
|
| 63 |
-
# TEXT CHATBOT
|
| 64 |
-
# =====================================================
|
| 65 |
|
| 66 |
-
def chatbot_text(
|
| 67 |
-
if not
|
| 68 |
return history, ""
|
| 69 |
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
chat_model=_llm,
|
| 74 |
-
)
|
| 75 |
-
|
| 76 |
-
quellen_block = format_sources_markdown(sources)
|
| 77 |
-
|
| 78 |
-
history = history + [
|
| 79 |
-
{"role": "user", "content": user_message},
|
| 80 |
-
{"role": "assistant", "content": answer_text + quellen_block},
|
| 81 |
-
]
|
| 82 |
-
|
| 83 |
return history, ""
|
| 84 |
|
| 85 |
-
#
|
| 86 |
-
# VOICE CHATBOT
|
| 87 |
-
# =====================================================
|
| 88 |
|
| 89 |
-
def chatbot_voice(
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
if not text:
|
| 93 |
-
return history, None, ""
|
| 94 |
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
# 2. RAG trả lời
|
| 99 |
-
answer_text, sources = answer(
|
| 100 |
-
question=text,
|
| 101 |
-
retriever=_retriever,
|
| 102 |
-
chat_model=_llm,
|
| 103 |
-
)
|
| 104 |
-
quellen_block = format_sources_markdown(sources)
|
| 105 |
|
| 106 |
-
|
| 107 |
-
history = history + [{"role": "assistant", "content": bot_msg}]
|
| 108 |
|
| 109 |
-
|
| 110 |
-
|
| 111 |
|
| 112 |
-
return history, audio, ""
|
| 113 |
|
| 114 |
# =====================================================
|
| 115 |
# LAST ANSWER → TTS
|
|
|
|
| 59 |
|
| 60 |
return "\n".join(out)
|
| 61 |
|
| 62 |
+
# ===================== TEXT CHAT =====================
|
|
|
|
|
|
|
| 63 |
|
| 64 |
+
def chatbot_text(msg, history):
|
| 65 |
+
if not msg:
|
| 66 |
return history, ""
|
| 67 |
|
| 68 |
+
ans, sources = answer(msg, retriever, llm)
|
| 69 |
+
history.append({"role": "user", "content": msg})
|
| 70 |
+
history.append({"role": "assistant", "content": ans + format_sources(sources)})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
return history, ""
|
| 72 |
|
| 73 |
+
# ===================== VOICE CHAT =====================
|
|
|
|
|
|
|
| 74 |
|
| 75 |
+
def chatbot_voice(audio, history):
|
| 76 |
+
text = transcribe_audio(audio)
|
| 77 |
+
history.append({"role": "user", "content": text})
|
|
|
|
|
|
|
| 78 |
|
| 79 |
+
ans, sources = answer(text, retriever, llm)
|
| 80 |
+
bot_msg = ans + format_sources(sources)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
+
history.append({"role": "assistant", "content": bot_msg})
|
|
|
|
| 83 |
|
| 84 |
+
tts_audio = synthesize_speech(bot_msg)
|
| 85 |
+
return history, tts_audio, ""
|
| 86 |
|
|
|
|
| 87 |
|
| 88 |
# =====================================================
|
| 89 |
# LAST ANSWER → TTS
|