Yaron Koresh commited on
Commit
706151f
·
verified ·
1 Parent(s): 397731d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -3
app.py CHANGED
@@ -54,8 +54,8 @@ def translate(text,lang):
54
  'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15',
55
  'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15'
56
  ]
57
- query_text = f'what is the {lang} translation of {text}'
58
- url = f'http://google.com/search?q={query_text}'
59
 
60
  print(url)
61
 
@@ -80,7 +80,7 @@ def translate(text,lang):
80
  if trgt_lang == lang:
81
  translated = trgt_text
82
  except:
83
- raise Exception("Translation Error!")
84
 
85
  ret = re.sub(f'[{string.punctuation}]', '', re.sub('[\s+]', ' ', translated)).lower().strip()
86
  print(ret)
 
54
  'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15',
55
  'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15'
56
  ]
57
+ query_text = f'Please translate {text} into {lang}'
58
+ url = f'https://www.google.com/search?q={query_text}'
59
 
60
  print(url)
61
 
 
80
  if trgt_lang == lang:
81
  translated = trgt_text
82
  except:
83
+ raise print(f'Warning: Could not translate "{text}" into {lang}!')
84
 
85
  ret = re.sub(f'[{string.punctuation}]', '', re.sub('[\s+]', ' ', translated)).lower().strip()
86
  print(ret)