Yaron Koresh commited on
Commit
3ed5fef
·
verified ·
1 Parent(s): 49e1030

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -24,11 +24,11 @@ else:
24
  pipe = DiffusionPipeline.from_pretrained(model_id, use_safetensors=True)
25
  pipe = pipe.to(device)
26
 
27
- def he_to_en(prompt):
28
- html_str = requests.get( url = "https://translate.google.com", params = {"sl": "iw", "tl": "en", "op": "translate", "text": prompt} ).text()
29
  tree = fromstring(html_str)
30
- english = tree.xpath('span[lang="en"]/span/span/text()')[0]
31
- return english
32
 
33
  def generate_random_string(length):
34
  characters = string.ascii_letters + string.digits
@@ -37,7 +37,7 @@ def generate_random_string(length):
37
  @spaces.GPU(25)
38
  def infer(prompt):
39
  name = generate_random_string(12)+".png"
40
- image = pipe(he_to_en(prompt)).images[0].save(name)
41
  return name
42
 
43
  css="""
 
24
  pipe = DiffusionPipeline.from_pretrained(model_id, use_safetensors=True)
25
  pipe = pipe.to(device)
26
 
27
+ def translate(text,lang):
28
+ html_str = requests.get( url = "https://translate.google.com", params = {"sl": "auto", "tl": lang, "op": "translate", "text": text} ).text()
29
  tree = fromstring(html_str)
30
+ translated = tree.xpath('span[lang="'+lang+'"]/span/span/text()')[0]
31
+ return translated
32
 
33
  def generate_random_string(length):
34
  characters = string.ascii_letters + string.digits
 
37
  @spaces.GPU(25)
38
  def infer(prompt):
39
  name = generate_random_string(12)+".png"
40
+ image = pipe(translate(prompt,"en")).images[0].save(name)
41
  return name
42
 
43
  css="""