Spaces:
Runtime error
Runtime error
Yaron Koresh
commited on
Update app.py
Browse files
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 = '
|
| 58 |
-
url = f'
|
| 59 |
|
| 60 |
print(url)
|
| 61 |
|
|
@@ -72,12 +72,12 @@ def translate(text,lang):
|
|
| 72 |
translated = text
|
| 73 |
|
| 74 |
try:
|
| 75 |
-
src_lang = html.xpath('//*[@class="source-language"]')[0].text_content().strip()
|
| 76 |
-
trgt_lang = html.xpath('//*[@class="target-language"]')[0].text_content().strip()
|
| 77 |
-
src_text = html.xpath('//*[@id="tw-source-text"]/*')[0].text_content().strip()
|
| 78 |
-
trgt_text = html.xpath('//*[@id="tw-target-text"]/*')[0].text_content().strip()
|
| 79 |
|
| 80 |
-
if trgt_lang
|
| 81 |
translated = trgt_text
|
| 82 |
except:
|
| 83 |
raise Exception("Translation Error!")
|
|
|
|
| 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 |
|
|
|
|
| 72 |
translated = text
|
| 73 |
|
| 74 |
try:
|
| 75 |
+
src_lang = html.xpath('//*[@class="source-language"]')[0].text_content().lower().strip()
|
| 76 |
+
trgt_lang = html.xpath('//*[@class="target-language"]')[0].text_content().lower().strip()
|
| 77 |
+
src_text = html.xpath('//*[@id="tw-source-text"]/*')[0].text_content().lower().strip()
|
| 78 |
+
trgt_text = html.xpath('//*[@id="tw-target-text"]/*')[0].text_content().lower().strip()
|
| 79 |
|
| 80 |
+
if trgt_lang == lang:
|
| 81 |
translated = trgt_text
|
| 82 |
except:
|
| 83 |
raise Exception("Translation Error!")
|