Spaces:
Running
Running
Yaron Koresh
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -112,6 +112,9 @@ function custom(){
|
|
112 |
|
113 |
def run(cmd):
|
114 |
return str(subprocess.run(cmd, shell=True, capture_output=True, env=None).stdout)
|
|
|
|
|
|
|
115 |
|
116 |
@gpu(string(string,string),device=True,inline=True)
|
117 |
def translate(text,lang):
|
@@ -142,10 +145,10 @@ def translate(text,lang):
|
|
142 |
).content)
|
143 |
translated = text
|
144 |
try:
|
145 |
-
src_lang =
|
146 |
-
trgt_lang =
|
147 |
-
src_text =
|
148 |
-
trgt_text =
|
149 |
if trgt_lang == lang:
|
150 |
translated = trgt_text
|
151 |
except:
|
|
|
112 |
|
113 |
def run(cmd):
|
114 |
return str(subprocess.run(cmd, shell=True, capture_output=True, env=None).stdout)
|
115 |
+
|
116 |
+
def xpath(str,pattern):
|
117 |
+
return fromstring(str).xpath(pattern)[0].text_content().lower().strip()
|
118 |
|
119 |
@gpu(string(string,string),device=True,inline=True)
|
120 |
def translate(text,lang):
|
|
|
145 |
).content)
|
146 |
translated = text
|
147 |
try:
|
148 |
+
src_lang = xpath(content,'//*[@class="source-language"]')
|
149 |
+
trgt_lang = xpath(content,'//*[@class="target-language"]')
|
150 |
+
src_text = xpath(content,'//*[@id="tw-source-text"]/*')
|
151 |
+
trgt_text = xpath(content,'//*[@id="tw-target-text"]/*')
|
152 |
if trgt_lang == lang:
|
153 |
translated = trgt_text
|
154 |
except:
|