Spaces:
Sleeping
Sleeping
Yaron Koresh
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -39,9 +39,12 @@ def translate(text,lang):
|
|
39 |
if text == "" or lang == "":
|
40 |
return ""
|
41 |
|
|
|
|
|
|
|
42 |
if len(text) > 38:
|
43 |
raise Exception("Translation Error: Too long text!")
|
44 |
-
|
45 |
user_agents = [
|
46 |
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36',
|
47 |
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36',
|
@@ -56,7 +59,7 @@ def translate(text,lang):
|
|
56 |
|
57 |
resp = requests.get(
|
58 |
url = url,
|
59 |
-
params = {'q': f'{lang} translate {text}'},
|
60 |
headers = {
|
61 |
'User-Agent': random.choice(user_agents)
|
62 |
}
|
@@ -66,7 +69,7 @@ def translate(text,lang):
|
|
66 |
html = fromstring(content)
|
67 |
|
68 |
translated = text
|
69 |
-
|
70 |
try:
|
71 |
src_lang = html.xpath('//span[@class="source-language"]')[0].text_content().strip()
|
72 |
trgt_lang = html.xpath('//span[@class="target-language"]')[0].text_content().strip()
|
|
|
39 |
if text == "" or lang == "":
|
40 |
return ""
|
41 |
|
42 |
+
print(text)
|
43 |
+
print(lang)
|
44 |
+
|
45 |
if len(text) > 38:
|
46 |
raise Exception("Translation Error: Too long text!")
|
47 |
+
|
48 |
user_agents = [
|
49 |
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36',
|
50 |
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36',
|
|
|
59 |
|
60 |
resp = requests.get(
|
61 |
url = url,
|
62 |
+
params = {'q': f'{lang} translate {text}'.replace(" ","%20")},
|
63 |
headers = {
|
64 |
'User-Agent': random.choice(user_agents)
|
65 |
}
|
|
|
69 |
html = fromstring(content)
|
70 |
|
71 |
translated = text
|
72 |
+
|
73 |
try:
|
74 |
src_lang = html.xpath('//span[@class="source-language"]')[0].text_content().strip()
|
75 |
trgt_lang = html.xpath('//span[@class="target-language"]')[0].text_content().strip()
|