Spaces:
Running
Running
Yaron Koresh
commited on
Update app.py
Browse files
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 =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
|