Yaron Koresh commited on
Commit
f2fa35d
·
verified ·
1 Parent(s): 77c5e2a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -4
app.py CHANGED
@@ -49,7 +49,12 @@ def translate(text,lang):
49
  content = resp.content
50
  html = fromstring(content)
51
  rslt = html.xpath('//pre[@aria-label="Translated text"]/span')
52
- translated = rslt[0].text.strip()
 
 
 
 
 
53
  ret = re.sub(f'[{string.punctuation}]', '', re.sub('[\s+]', ' ', translated)).lower().strip()
54
  print(ret)
55
  return ret
@@ -58,12 +63,12 @@ def generate_random_string(length):
58
  characters = string.ascii_letters + string.digits
59
  return ''.join(random.choice(characters) for _ in range(length))
60
 
61
- @spaces.GPU(120)
62
  def Piper(_do, _dont):
63
  return pipe(
64
  _do,
65
- height=448,
66
- width=448,
67
  negative_prompt=_dont,
68
  num_inference_steps=400,
69
  guidance_scale=10
 
49
  content = resp.content
50
  html = fromstring(content)
51
  rslt = html.xpath('//pre[@aria-label="Translated text"]/span')
52
+ translated = text
53
+ try:
54
+ t = rslt[0].text.strip()
55
+ translated = t
56
+ except:
57
+ print(f'"{text}" is already in {lang}!')
58
  ret = re.sub(f'[{string.punctuation}]', '', re.sub('[\s+]', ' ', translated)).lower().strip()
59
  print(ret)
60
  return ret
 
63
  characters = string.ascii_letters + string.digits
64
  return ''.join(random.choice(characters) for _ in range(length))
65
 
66
+ @spaces.GPU(duration=120)
67
  def Piper(_do, _dont):
68
  return pipe(
69
  _do,
70
+ height=480,
71
+ width=480,
72
  negative_prompt=_dont,
73
  num_inference_steps=400,
74
  guidance_scale=10