Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,8 +3,8 @@ import gradio as gr
|
|
| 3 |
|
| 4 |
# Pipeline
|
| 5 |
# Translate from Japanese to English
|
| 6 |
-
translator_ja_to_en = pipeline("translation_ja_to_en", model="Helsinki-NLP/opus-mt-ja-en")
|
| 7 |
-
|
| 8 |
|
| 9 |
# Summerize from English to English
|
| 10 |
# summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
|
@@ -15,7 +15,7 @@ summarizer = pipeline("summarization", model="google/pegasus-large")
|
|
| 15 |
translator_en_to_ja = pipeline("translation_en_to_ja", model="ZenXir/marian-finetuned-kde4-en-to-ja")
|
| 16 |
|
| 17 |
|
| 18 |
-
maxlength =
|
| 19 |
|
| 20 |
def summarize_and_translate(text):
|
| 21 |
# check max text length
|
|
@@ -23,13 +23,13 @@ def summarize_and_translate(text):
|
|
| 23 |
return f"γ¨γ©γΌοΌ{maxlength}ζεδ»₯ε
γ§ε
₯εγγ¦γγ γγ\nError: The text cannot exceed {maxlength} characters. Please shorten your text."
|
| 24 |
|
| 25 |
# Translate from Japanese to English
|
| 26 |
-
translated_text_to_en = translator_ja_to_en(text, max_length=maxlength+
|
| 27 |
|
| 28 |
# Summerize from English to English
|
| 29 |
summary_in_en = summarizer(translated_text_to_en, min_length=5, max_length=50)[0]['summary_text']
|
| 30 |
|
| 31 |
# Translate from English to Japanese
|
| 32 |
-
summary_in_ja = translator_en_to_ja(summary_in_en, max_length=
|
| 33 |
|
| 34 |
return summary_in_ja
|
| 35 |
|
|
|
|
| 3 |
|
| 4 |
# Pipeline
|
| 5 |
# Translate from Japanese to English
|
| 6 |
+
# translator_ja_to_en = pipeline("translation_ja_to_en", model="Helsinki-NLP/opus-mt-ja-en")
|
| 7 |
+
translator_ja_to_en = pipeline("translation_ja_to_en", model="japanese-denim/nllb-finetuned-naga-to-eng")
|
| 8 |
|
| 9 |
# Summerize from English to English
|
| 10 |
# summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
|
|
|
| 15 |
translator_en_to_ja = pipeline("translation_en_to_ja", model="ZenXir/marian-finetuned-kde4-en-to-ja")
|
| 16 |
|
| 17 |
|
| 18 |
+
maxlength = 100
|
| 19 |
|
| 20 |
def summarize_and_translate(text):
|
| 21 |
# check max text length
|
|
|
|
| 23 |
return f"γ¨γ©γΌοΌ{maxlength}ζεδ»₯ε
γ§ε
₯εγγ¦γγ γγ\nError: The text cannot exceed {maxlength} characters. Please shorten your text."
|
| 24 |
|
| 25 |
# Translate from Japanese to English
|
| 26 |
+
translated_text_to_en = translator_ja_to_en(text, max_length=maxlength+50)[0]['translation_text']
|
| 27 |
|
| 28 |
# Summerize from English to English
|
| 29 |
summary_in_en = summarizer(translated_text_to_en, min_length=5, max_length=50)[0]['summary_text']
|
| 30 |
|
| 31 |
# Translate from English to Japanese
|
| 32 |
+
summary_in_ja = translator_en_to_ja(summary_in_en, max_length=200)[0]['translation_text']
|
| 33 |
|
| 34 |
return summary_in_ja
|
| 35 |
|