Spaces:
Running
Running
Yaron Koresh
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -113,9 +113,12 @@ function custom(){
|
|
113 |
def run(cmd):
|
114 |
return str(subprocess.run(cmd, shell=True, capture_output=True, env=None).stdout)
|
115 |
|
116 |
-
def
|
117 |
-
|
118 |
-
|
|
|
|
|
|
|
119 |
@gpu(string(string,string),device=True,inline=True)
|
120 |
def translate(text,lang):
|
121 |
|
@@ -144,15 +147,12 @@ def translate(text,lang):
|
|
144 |
}
|
145 |
).content)
|
146 |
translated = text
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
translated = trgt_text
|
154 |
-
except:
|
155 |
-
print(f'Translation Warning: Failed To Translate!')
|
156 |
ret = re.sub(f'[{string.punctuation}]', '', re.sub('[\s+]', ' ', translated)).lower().strip()
|
157 |
print(ret)
|
158 |
return ret
|
|
|
113 |
def run(cmd):
|
114 |
return str(subprocess.run(cmd, shell=True, capture_output=True, env=None).stdout)
|
115 |
|
116 |
+
def xpath_finder(str,pattern):
|
117 |
+
try:
|
118 |
+
return ""+fromstring(str).xpath(pattern)[0].text_content().lower().strip()
|
119 |
+
except:
|
120 |
+
return ""
|
121 |
+
|
122 |
@gpu(string(string,string),device=True,inline=True)
|
123 |
def translate(text,lang):
|
124 |
|
|
|
147 |
}
|
148 |
).content)
|
149 |
translated = text
|
150 |
+
src_lang = xpath_finder(content,'//*[@class="source-language"]')
|
151 |
+
trgt_lang = xpath_finder(content,'//*[@class="target-language"]')
|
152 |
+
src_text = xpath_finder(content,'//*[@id="tw-source-text"]/*')
|
153 |
+
trgt_text = xpath_finder(content,'//*[@id="tw-target-text"]/*')
|
154 |
+
if trgt_lang == lang:
|
155 |
+
translated = trgt_text
|
|
|
|
|
|
|
156 |
ret = re.sub(f'[{string.punctuation}]', '', re.sub('[\s+]', ' ', translated)).lower().strip()
|
157 |
print(ret)
|
158 |
return ret
|