Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,10 @@
|
|
1 |
import gradio as gr
|
2 |
import logging, langdetect
|
3 |
from huggingface_hub import InferenceClient
|
4 |
-
from
|
5 |
|
6 |
# Khởi tạo client HF và translator
|
7 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
8 |
-
translator_vi2en = GoogleTranslator(source='vi', target='en')
|
9 |
-
translator_en2vi = GoogleTranslator(source='en', target='vi')
|
10 |
|
11 |
logging.basicConfig(level=logging.INFO)
|
12 |
|
@@ -26,7 +24,8 @@ def respond(
|
|
26 |
messages = [{"role": "system", "content": system_message}]
|
27 |
|
28 |
# Dịch câu hỏi của người dùng từ tiếng Việt sang tiếng Anh
|
29 |
-
|
|
|
30 |
|
31 |
# Thêm các tin nhắn lịch sử vào messages
|
32 |
for val in history:
|
@@ -56,7 +55,8 @@ def respond(
|
|
56 |
except Exception as e:
|
57 |
return f"Error: {str(e)}"
|
58 |
|
59 |
-
|
|
|
60 |
logging.info(f"Successfully generated text: {response}")
|
61 |
|
62 |
return response if langdetect.detect(response) == 'vi' else response_vi
|
|
|
1 |
import gradio as gr
|
2 |
import logging, langdetect
|
3 |
from huggingface_hub import InferenceClient
|
4 |
+
from textblob import TextBlob
|
5 |
|
6 |
# Khởi tạo client HF và translator
|
7 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
|
|
|
|
8 |
|
9 |
logging.basicConfig(level=logging.INFO)
|
10 |
|
|
|
24 |
messages = [{"role": "system", "content": system_message}]
|
25 |
|
26 |
# Dịch câu hỏi của người dùng từ tiếng Việt sang tiếng Anh
|
27 |
+
message = TextBlob(message)
|
28 |
+
message_en = message.translate(to='en')
|
29 |
|
30 |
# Thêm các tin nhắn lịch sử vào messages
|
31 |
for val in history:
|
|
|
55 |
except Exception as e:
|
56 |
return f"Error: {str(e)}"
|
57 |
|
58 |
+
response_blob = TextBlob(response)
|
59 |
+
response_vi = response_blob.translate(to='vi')
|
60 |
logging.info(f"Successfully generated text: {response}")
|
61 |
|
62 |
return response if langdetect.detect(response) == 'vi' else response_vi
|