Yaron Koresh commited on
Commit
4c5f7a7
·
verified ·
1 Parent(s): c7944d8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -1
app.py CHANGED
@@ -723,7 +723,22 @@ def translate(txt,to_lang="en",from_lang=False):
723
  return txt
724
 
725
  translator = Translator(from_lang=from_lang,to_lang=to_lang)
726
- translation = translator.translate(txt)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
727
  log(f'RET translate with translation as {translation}')
728
  return translation
729
 
 
723
  return txt
724
 
725
  translator = Translator(from_lang=from_lang,to_lang=to_lang)
726
+ translation = ""
727
+ if len(txt) > 490:
728
+ words = txt.split()
729
+ while len(words) > 0:
730
+ chunk = ""
731
+ while len(chunk) < 490:
732
+ chunk = chunk + " " + words[0]
733
+ words = words[1:]
734
+ if len(chunk) > 490:
735
+ _words = chunk.split()
736
+ words = [_words[-1], *words]
737
+ chunk = _words[:-1]
738
+ translation = translation + " " + translator.translate(chunk)
739
+ else:
740
+ translation = translator.translate(txt)
741
+ translation = translation.strip()
742
  log(f'RET translate with translation as {translation}')
743
  return translation
744