Spaces:
Build error
Build error
Add multiline capabilities
Browse files
app.py
CHANGED
|
@@ -9,18 +9,33 @@ def translate(sentence):
|
|
| 9 |
outputs = infer.generate(input_ids, max_new_tokens = len(sentence.split(' '))*10)
|
| 10 |
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
title = "English to Middle English Translator"
|
| 13 |
description = """
|
| 14 |
-
This translator is trained on about
|
| 15 |
<br>
|
| 16 |
It's still a work in progress.
|
|
|
|
| 17 |
"""
|
| 18 |
-
article = '''
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
gr.Interface(
|
| 20 |
-
fn=
|
| 21 |
inputs=gr.Textbox(lines=1, placeholder="Enter text to translate."),
|
| 22 |
outputs="text",
|
| 23 |
title=title,
|
| 24 |
description=description,
|
| 25 |
article = article,
|
| 26 |
-
).launch()
|
|
|
|
| 9 |
outputs = infer.generate(input_ids, max_new_tokens = len(sentence.split(' '))*10)
|
| 10 |
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 11 |
|
| 12 |
+
def translate_multiline(sentence):
|
| 13 |
+
if len(sentence.split() > 300):
|
| 14 |
+
print('Please insert less text')
|
| 15 |
+
if '\n' in sentence:
|
| 16 |
+
lines = sentence.split('\n')
|
| 17 |
+
translated_lines = [translate(line) for line in lines if len(line) > 0]
|
| 18 |
+
return '\n'.join(translated_lines)
|
| 19 |
+
else:
|
| 20 |
+
return translate(sentence)
|
| 21 |
+
|
| 22 |
title = "English to Middle English Translator"
|
| 23 |
description = """
|
| 24 |
+
This translator is trained on about 70,000 English/Middle English paired sentences.
|
| 25 |
<br>
|
| 26 |
It's still a work in progress.
|
| 27 |
+
<br>
|
| 28 |
"""
|
| 29 |
+
article = '''
|
| 30 |
+
<br>
|
| 31 |
+
You can improve results by removing conjunctions (hadn't -> had not)
|
| 32 |
+
'''
|
| 33 |
+
|
| 34 |
gr.Interface(
|
| 35 |
+
fn=translate_multiline,
|
| 36 |
inputs=gr.Textbox(lines=1, placeholder="Enter text to translate."),
|
| 37 |
outputs="text",
|
| 38 |
title=title,
|
| 39 |
description=description,
|
| 40 |
article = article,
|
| 41 |
+
).launch()
|