Spaces:
Runtime error
Runtime error
yizhangliu
commited on
Commit
•
ebc5193
1
Parent(s):
dac6aed
Update app.py
Browse files
app.py
CHANGED
@@ -9,22 +9,26 @@ from encoder import get_encoder
|
|
9 |
|
10 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
11 |
|
12 |
-
|
|
|
|
|
|
|
13 |
def getTextTrans(text, source='zh', target='en'):
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
19 |
|
20 |
-
if not is_chinese(text) and target == 'en':
|
21 |
-
|
22 |
|
23 |
-
try:
|
24 |
-
|
25 |
-
|
26 |
-
except Exception as e:
|
27 |
-
|
28 |
|
29 |
session_token = os.environ.get('SessionToken')
|
30 |
# logger.info(f"session_token_: {session_token}")
|
|
|
9 |
|
10 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
11 |
|
12 |
+
from utils import get_tmt_client, getTextTrans_tmt
|
13 |
+
tmt_client = get_tmt_client()
|
14 |
+
|
15 |
+
# language_translation_model = hub.Module(directory=f'./baidu_translate')
|
16 |
def getTextTrans(text, source='zh', target='en'):
|
17 |
+
return getTextTrans_tmt(tmt_client, text, source, target)
|
18 |
+
# def is_chinese(string):
|
19 |
+
# for ch in string:
|
20 |
+
# if u'\u4e00' <= ch <= u'\u9fff':
|
21 |
+
# return True
|
22 |
+
# return False
|
23 |
|
24 |
+
# if not is_chinese(text) and target == 'en':
|
25 |
+
# return text
|
26 |
|
27 |
+
# try:
|
28 |
+
# text_translation = language_translation_model.translate(text, source, target)
|
29 |
+
# return text_translation
|
30 |
+
# except Exception as e:
|
31 |
+
# return text
|
32 |
|
33 |
session_token = os.environ.get('SessionToken')
|
34 |
# logger.info(f"session_token_: {session_token}")
|