Update app.py
Browse files
app.py
CHANGED
|
@@ -101,6 +101,8 @@ def chat_with_model(prompt, system_prompt, chatbot_display, internal_history,lan
|
|
| 101 |
print("❌ Invalid key.")
|
| 102 |
return "", chatbot_display, internal_history
|
| 103 |
prompt = prompt.replace(expected_key, "")
|
|
|
|
|
|
|
| 104 |
# 1. Khởi tạo nếu đây là lần chạy đầu tiên
|
| 105 |
# chatbot_display là [[user_msg, ai_msg], ...]
|
| 106 |
if chatbot_display is None:
|
|
@@ -138,7 +140,9 @@ def chat_with_model(prompt, system_prompt, chatbot_display, internal_history,lan
|
|
| 138 |
|
| 139 |
# 5. Decode *chỉ* phần trả lời mới
|
| 140 |
response_text = tokenizer.decode(output_tokens[0][inputs.shape[-1]:], skip_special_tokens=True)
|
| 141 |
-
translated =
|
|
|
|
|
|
|
| 142 |
print(response_text)
|
| 143 |
# 6. Cập nhật "bộ nhớ" (gr.State) với lượt nói MỚI
|
| 144 |
internal_history.append({"role": "user", "content": prompt})
|
|
|
|
| 101 |
print("❌ Invalid key.")
|
| 102 |
return "", chatbot_display, internal_history
|
| 103 |
prompt = prompt.replace(expected_key, "")
|
| 104 |
+
if lang not None:
|
| 105 |
+
prompt = translate_text(prompt,lang+"-en")
|
| 106 |
# 1. Khởi tạo nếu đây là lần chạy đầu tiên
|
| 107 |
# chatbot_display là [[user_msg, ai_msg], ...]
|
| 108 |
if chatbot_display is None:
|
|
|
|
| 140 |
|
| 141 |
# 5. Decode *chỉ* phần trả lời mới
|
| 142 |
response_text = tokenizer.decode(output_tokens[0][inputs.shape[-1]:], skip_special_tokens=True)
|
| 143 |
+
translated = response_text
|
| 144 |
+
if(lang not None)
|
| 145 |
+
translated = translate_text(response_text,"en-"+lang)
|
| 146 |
print(response_text)
|
| 147 |
# 6. Cập nhật "bộ nhớ" (gr.State) với lượt nói MỚI
|
| 148 |
internal_history.append({"role": "user", "content": prompt})
|