Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,18 +3,16 @@ 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 |
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")
|
11 |
summarizer = pipeline("summarization", model="google/pegasus-large")
|
12 |
|
13 |
# Translate from English to Japanese
|
14 |
-
# translator_en_to_ja = pipeline("translation_en_to_ja", model="Helsinki-NLP/opus-tatoeba-en-ja")
|
15 |
translator_en_to_ja = pipeline("translation_en_to_ja", model="ZenXir/marian-finetuned-kde4-en-to-ja")
|
16 |
|
17 |
-
|
|
|
18 |
|
19 |
def summarize_and_translate(text):
|
20 |
# check max text length
|
@@ -22,22 +20,22 @@ def summarize_and_translate(text):
|
|
22 |
return f"エラー:{maxlength}文字以内で入力してください\nError: The text cannot exceed {maxlength} characters. Please shorten your text."
|
23 |
|
24 |
# Translate from Japanese to English
|
25 |
-
translated_text_to_en = translator_ja_to_en(text, max_length=maxlength+
|
26 |
|
27 |
# Summerize from English to English
|
28 |
-
summary_in_en = summarizer(translated_text_to_en, min_length=50, max_length=
|
29 |
|
30 |
# Translate from English to Japanese
|
31 |
-
summary_in_ja = translator_en_to_ja(summary_in_en, max_length=
|
32 |
|
33 |
return summary_in_ja
|
34 |
|
35 |
demo = gr.Interface(
|
36 |
fn=summarize_and_translate,
|
37 |
-
inputs=gr.Textbox(lines=5, placeholder= f"{maxlength}
|
38 |
-
outputs=gr.Textbox(lines=5, label="日本語要約 Summarized Japanese"),
|
39 |
title="日本語要約 Jpanese Summarizer",
|
40 |
-
description=f"日本語の文章を入力すると、日本語の要約が表示されます。
|
41 |
)
|
42 |
|
43 |
demo.launch()
|
|
|
3 |
|
4 |
# Pipeline
|
5 |
# Translate from Japanese to English
|
|
|
6 |
translator_ja_to_en = pipeline("translation_ja_to_en", model="japanese-denim/nllb-finetuned-naga-to-eng")
|
7 |
|
8 |
# Summerize from English to English
|
|
|
9 |
summarizer = pipeline("summarization", model="google/pegasus-large")
|
10 |
|
11 |
# Translate from English to Japanese
|
|
|
12 |
translator_en_to_ja = pipeline("translation_en_to_ja", model="ZenXir/marian-finetuned-kde4-en-to-ja")
|
13 |
|
14 |
+
|
15 |
+
maxlength = 1000
|
16 |
|
17 |
def summarize_and_translate(text):
|
18 |
# check max text length
|
|
|
20 |
return f"エラー:{maxlength}文字以内で入力してください\nError: The text cannot exceed {maxlength} characters. Please shorten your text."
|
21 |
|
22 |
# Translate from Japanese to English
|
23 |
+
translated_text_to_en = translator_ja_to_en(text, max_length=maxlength+100)[0]['translation_text']
|
24 |
|
25 |
# Summerize from English to English
|
26 |
+
summary_in_en = summarizer(translated_text_to_en, min_length=50, max_length=300)[0]['summary_text']
|
27 |
|
28 |
# Translate from English to Japanese
|
29 |
+
summary_in_ja = translator_en_to_ja(summary_in_en, max_length=300)[0]['translation_text']
|
30 |
|
31 |
return summary_in_ja
|
32 |
|
33 |
demo = gr.Interface(
|
34 |
fn=summarize_and_translate,
|
35 |
+
inputs=gr.Textbox(lines=5, placeholder= f"{maxlength}文字以内で日本語の文章を入力してください\nPlease enter Japanese text within a {maxlength}-character limit"),
|
36 |
+
outputs=gr.Textbox(lines=5, label="日本語要約 (Summarized Japanese)"),
|
37 |
title="日本語要約 Jpanese Summarizer",
|
38 |
+
description=f"日本語の文章を入力すると、日本語の要約が表示されます。(Enter Japanese text up to {maxlength} characters to see its summary)"
|
39 |
)
|
40 |
|
41 |
demo.launch()
|