yizhangliu commited on
Commit
ebc5193
1 Parent(s): dac6aed

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -13
app.py CHANGED
@@ -9,22 +9,26 @@ from encoder import get_encoder
9
 
10
  openai.api_key = os.getenv("OPENAI_API_KEY")
11
 
12
- language_translation_model = hub.Module(directory=f'./baidu_translate')
 
 
 
13
  def getTextTrans(text, source='zh', target='en'):
14
- def is_chinese(string):
15
- for ch in string:
16
- if u'\u4e00' <= ch <= u'\u9fff':
17
- return True
18
- return False
 
19
 
20
- if not is_chinese(text) and target == 'en':
21
- return text
22
 
23
- try:
24
- text_translation = language_translation_model.translate(text, source, target)
25
- return text_translation
26
- except Exception as e:
27
- return text
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}")