Yaron Koresh commited on
Commit
ecc81cb
·
verified ·
1 Parent(s): e0d59c8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
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 etree
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
- ).text
41
- tree = etree.HTML(html_str)
42
- translated = tree.xpath(f'//span[@lang="{lang}"]/span/span[text()]')[0].text.strip()
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):