Yaron Koresh commited on
Commit
369a3fa
·
verified ·
1 Parent(s): 5ee59c2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -65,14 +65,15 @@ def translate(text,lang):
65
  content = resp.content
66
  html = fromstring(content)
67
 
68
- #src = html.xpath('//pre[@data-placeholder="Enter text"]/textarea')[0].text.strip()
69
-
70
  translated = text
71
 
72
- try:
73
- trgt = html.xpath('//span[@class="target-language"]')[0].text.strip()
74
- rslt = html.xpath('//pre[@aria-label="Translated text"]/span')[0].text.strip()
75
- if trgt.lower() == lang.lower():
 
 
 
76
  translated = rslt
77
  except:
78
  raise Exception("Translation Error!")
 
65
  content = resp.content
66
  html = fromstring(content)
67
 
 
 
68
  translated = text
69
 
70
+ try:
71
+ src_lang = html.xpath('//span[@class="source-language"]/span')[0].text_content().strip()
72
+ trgt_lang = html.xpath('//span[@class="target-language"]')[0].text_content().strip()
73
+ src_text = html.xpath('//pre[@id="tw-source-text"]/span')[0].text_content().strip()
74
+ trgt_text = html.xpath('//pre[@id="tw-target-text"]/span')[0].text_content().strip()
75
+
76
+ if trgt_lang.lower() == lang.lower():
77
  translated = rslt
78
  except:
79
  raise Exception("Translation Error!")