Spaces:
Running
Running
liuyizhang
commited on
Commit
·
dc00461
1
Parent(s):
6c492ea
update app.py
Browse files- app.py +17 -16
- requirements.txt +1 -0
app.py
CHANGED
|
@@ -7,26 +7,27 @@ import torch
|
|
| 7 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 8 |
from loguru import logger
|
| 9 |
|
| 10 |
-
|
| 11 |
-
tmt_client = get_tmt_client()
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
| 14 |
def getTextTrans(text, source='zh', target='en'):
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
# return False
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
|
| 31 |
space_ids = {
|
| 32 |
"spaces/stabilityai/stable-diffusion": "SD 2.1",
|
|
|
|
| 7 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 8 |
from loguru import logger
|
| 9 |
|
| 10 |
+
import subprocess
|
|
|
|
| 11 |
|
| 12 |
+
result = subprocess.run(['pip', 'list'], check=True)
|
| 13 |
+
print(f'pip list = {result}')
|
| 14 |
+
|
| 15 |
+
language_translation_model = hub.Module(directory=f'./baidu_translate')
|
| 16 |
def getTextTrans(text, source='zh', target='en'):
|
| 17 |
+
def is_chinese(string):
|
| 18 |
+
for ch in string:
|
| 19 |
+
if u'\u4e00' <= ch <= u'\u9fff':
|
| 20 |
+
return True
|
| 21 |
+
return False
|
|
|
|
| 22 |
|
| 23 |
+
if not is_chinese(text) and target == 'en':
|
| 24 |
+
return text
|
| 25 |
|
| 26 |
+
try:
|
| 27 |
+
text_translation = language_translation_model.translate(text, source, target)
|
| 28 |
+
return text_translation
|
| 29 |
+
except Exception as e:
|
| 30 |
+
return text
|
| 31 |
|
| 32 |
space_ids = {
|
| 33 |
"spaces/stabilityai/stable-diffusion": "SD 2.1",
|
requirements.txt
CHANGED
|
@@ -5,5 +5,6 @@ torch
|
|
| 5 |
gradio
|
| 6 |
paddlepaddle==2.3.2
|
| 7 |
paddlehub
|
|
|
|
| 8 |
loguru
|
| 9 |
tencentcloud-sdk-python
|
|
|
|
| 5 |
gradio
|
| 6 |
paddlepaddle==2.3.2
|
| 7 |
paddlehub
|
| 8 |
+
requests
|
| 9 |
loguru
|
| 10 |
tencentcloud-sdk-python
|