Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -30,7 +30,35 @@ from piper_phonemize import phonemize_codepoints, phonemize_espeak, tashkeel_run
|
|
30 |
|
31 |
#_LOGGER = logging.getLogger("piper_train.infer_onnx")
|
32 |
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
def detect_onnx_models(path):
|
35 |
onnx_models = glob.glob(path + '/*.onnx')
|
36 |
if len(onnx_models) > 1:
|
|
|
30 |
|
31 |
#_LOGGER = logging.getLogger("piper_train.infer_onnx")
|
32 |
|
33 |
+
import configparser
|
34 |
+
import os
|
35 |
+
|
36 |
+
class Translator:
|
37 |
+
def __init__(self):
|
38 |
+
self.configs = {}
|
39 |
+
|
40 |
+
def load_language(self, language_name):
|
41 |
+
if language_name not in self.configs:
|
42 |
+
config = configparser.ConfigParser()
|
43 |
+
config.read(os.path.join(os.getcwd(), "lng", f"{language_name}.lang"))
|
44 |
+
self.configs[language_name] = config
|
45 |
+
|
46 |
+
def translate(self, language_name, string):
|
47 |
+
if language_name == "en":
|
48 |
+
return string
|
49 |
+
elif language_name not in self.configs:
|
50 |
+
self.load_language(language_name)
|
51 |
+
config = self.configs[language_name]
|
52 |
+
try:
|
53 |
+
return config.get("Strings", string)
|
54 |
+
except (configparser.NoOptionError, configparser.NoSectionError):
|
55 |
+
if string:
|
56 |
+
return string
|
57 |
+
else:
|
58 |
+
raise Exception("language engine error: This translation is corrupt!")
|
59 |
+
return 0
|
60 |
+
#from translator import *
|
61 |
+
lan = Translator()
|
62 |
def detect_onnx_models(path):
|
63 |
onnx_models = glob.glob(path + '/*.onnx')
|
64 |
if len(onnx_models) > 1:
|