Yaron Koresh commited on
Commit
a00bc49
·
verified ·
1 Parent(s): f8a2ae6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -4
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 = fromstring(content).xpath('//*[@class="source-language"]')[0].text_content().lower().strip()
146
- trgt_lang = fromstring(content).xpath('//*[@class="target-language"]')[0].text_content().lower().strip()
147
- src_text = fromstring(content).xpath('//*[@id="tw-source-text"]/*')[0].text_content().lower().strip()
148
- trgt_text = fromstring(content).xpath('//*[@id="tw-target-text"]/*')[0].text_content().lower().strip()
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: