Spaces:
Sleeping
Sleeping
Yaron Koresh
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -7,7 +7,7 @@ from diffusers import StableDiffusionPipeline as DiffusionPipeline
|
|
7 |
import torch
|
8 |
from pathos.multiprocessing import ProcessingPool as ProcessPoolExecutor
|
9 |
import requests
|
10 |
-
from lxml import
|
11 |
|
12 |
pool = ProcessPoolExecutor(4)
|
13 |
pool.__enter__()
|
@@ -37,9 +37,9 @@ def translate(text,lang):
|
|
37 |
url = "http://translate.google.com",
|
38 |
params = {"sl": "auto", "tl": lang, "op": "translate", "text": text},
|
39 |
headers = {'User-Agent': random.choice(user_agents)}
|
40 |
-
).
|
41 |
-
|
42 |
-
translated =
|
43 |
return translated
|
44 |
|
45 |
def generate_random_string(length):
|
|
|
7 |
import torch
|
8 |
from pathos.multiprocessing import ProcessingPool as ProcessPoolExecutor
|
9 |
import requests
|
10 |
+
from lxml.html import fromstring
|
11 |
|
12 |
pool = ProcessPoolExecutor(4)
|
13 |
pool.__enter__()
|
|
|
37 |
url = "http://translate.google.com",
|
38 |
params = {"sl": "auto", "tl": lang, "op": "translate", "text": text},
|
39 |
headers = {'User-Agent': random.choice(user_agents)}
|
40 |
+
).content
|
41 |
+
root = fromstring(html_str)
|
42 |
+
translated = root.xpath(f'//span[@lang="{lang}"]/span/span')[0].text_content().strip()
|
43 |
return translated
|
44 |
|
45 |
def generate_random_string(length):
|