Spaces:
Running
Running
Yaron Koresh
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -35,14 +35,20 @@ def translate(text,lang):
|
|
35 |
'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',
|
36 |
'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15'
|
37 |
]
|
|
|
|
|
38 |
resp = requests.get(
|
39 |
-
url =
|
40 |
headers = {
|
41 |
'User-Agent': random.choice(user_agents)
|
42 |
}
|
43 |
)
|
44 |
print(resp)
|
45 |
-
|
|
|
|
|
|
|
|
|
46 |
return re.sub(f'[{string.punctuation}]', '', re.sub('[\s+]', ' ', translated)).lower().strip()
|
47 |
|
48 |
def generate_random_string(length):
|
|
|
35 |
'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',
|
36 |
'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15'
|
37 |
]
|
38 |
+
url = f'https://www.google.com/search?q=translate to {lang}: {text}'
|
39 |
+
print(url)
|
40 |
resp = requests.get(
|
41 |
+
url = url,
|
42 |
headers = {
|
43 |
'User-Agent': random.choice(user_agents)
|
44 |
}
|
45 |
)
|
46 |
print(resp)
|
47 |
+
content = resp.content
|
48 |
+
html = fromstring(content)
|
49 |
+
rslt = html.xpath('//span[@lang]')
|
50 |
+
print(rslt)
|
51 |
+
translated = rslt[0].text.strip()
|
52 |
return re.sub(f'[{string.punctuation}]', '', re.sub('[\s+]', ' ', translated)).lower().strip()
|
53 |
|
54 |
def generate_random_string(length):
|