Spaces:
Running
Running
Yaron Koresh
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -25,21 +25,28 @@ else:
|
|
25 |
|
26 |
def translate(text,lang):
|
27 |
user_agents = [
|
28 |
-
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/
|
29 |
-
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/
|
30 |
-
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/
|
31 |
-
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/
|
32 |
-
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/
|
33 |
-
'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'
|
34 |
'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15'
|
35 |
]
|
36 |
html_str = requests.get(
|
37 |
-
url = "
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
headers = {'User-Agent': random.choice(user_agents)}
|
40 |
).content
|
41 |
root = fromstring(html_str)
|
42 |
-
translated = root.xpath(f'//
|
43 |
return translated
|
44 |
|
45 |
def generate_random_string(length):
|
|
|
25 |
|
26 |
def translate(text,lang):
|
27 |
user_agents = [
|
28 |
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36',
|
29 |
+
'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',
|
30 |
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36',
|
31 |
+
'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',
|
32 |
+
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36',
|
33 |
+
'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',
|
34 |
'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15'
|
35 |
]
|
36 |
html_str = requests.get(
|
37 |
+
url = "https://www.bing.com/ttranslatev3?isVertical=1&&IG=25FEDD45BDB744CF85D101C01E6596C0&IID=translator.5026",
|
38 |
+
json = {
|
39 |
+
'fromLang': auto-detect,
|
40 |
+
'to': lang,
|
41 |
+
'token': MLfPKZhAXMWZirPdlpeEfN8DB58dZKR-,
|
42 |
+
'key': 1722119087131,
|
43 |
+
'text': text
|
44 |
+
'tryFetchingGenderDebiasedTranslations': true
|
45 |
+
},
|
46 |
headers = {'User-Agent': random.choice(user_agents)}
|
47 |
).content
|
48 |
root = fromstring(html_str)
|
49 |
+
translated = root.xpath(f'//textarea')[1].text().strip()
|
50 |
return translated
|
51 |
|
52 |
def generate_random_string(length):
|