Spaces:
Sleeping
Sleeping
Yaron Koresh
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -29,8 +29,16 @@ else:
|
|
29 |
pipe = pipe.to(device)
|
30 |
|
31 |
def translate(text,lang):
|
|
|
|
|
|
|
|
|
32 |
text = re.sub(f'[{string.punctuation}]', '', re.sub('[\s+]', ' ', text)).lower().strip()
|
33 |
lang = re.sub(f'[{string.punctuation}]', '', re.sub('[\s+]', ' ', lang)).lower().strip()
|
|
|
|
|
|
|
|
|
34 |
user_agents = [
|
35 |
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36',
|
36 |
'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',
|
@@ -40,7 +48,9 @@ def translate(text,lang):
|
|
40 |
'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',
|
41 |
'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15'
|
42 |
]
|
|
|
43 |
url = 'https://www.google.com/search'
|
|
|
44 |
resp = requests.get(
|
45 |
url = url,
|
46 |
params = {'q': f'{lang} translate {text}'},
|
@@ -48,6 +58,7 @@ def translate(text,lang):
|
|
48 |
'User-Agent': random.choice(user_agents)
|
49 |
}
|
50 |
)
|
|
|
51 |
content = resp.content
|
52 |
html = fromstring(content)
|
53 |
|
|
|
29 |
pipe = pipe.to(device)
|
30 |
|
31 |
def translate(text,lang):
|
32 |
+
|
33 |
+
if text == None or lang == None:
|
34 |
+
return ""
|
35 |
+
|
36 |
text = re.sub(f'[{string.punctuation}]', '', re.sub('[\s+]', ' ', text)).lower().strip()
|
37 |
lang = re.sub(f'[{string.punctuation}]', '', re.sub('[\s+]', ' ', lang)).lower().strip()
|
38 |
+
|
39 |
+
if text == "" or lang == "":
|
40 |
+
return ""
|
41 |
+
|
42 |
user_agents = [
|
43 |
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36',
|
44 |
'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',
|
|
|
48 |
'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',
|
49 |
'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15'
|
50 |
]
|
51 |
+
|
52 |
url = 'https://www.google.com/search'
|
53 |
+
|
54 |
resp = requests.get(
|
55 |
url = url,
|
56 |
params = {'q': f'{lang} translate {text}'},
|
|
|
58 |
'User-Agent': random.choice(user_agents)
|
59 |
}
|
60 |
)
|
61 |
+
|
62 |
content = resp.content
|
63 |
html = fromstring(content)
|
64 |
|