Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -73,36 +73,37 @@ def translate_text(text, source_lang, target_lang):
|
|
73 |
return translated_text
|
74 |
|
75 |
# Summarization function with multi-language support
|
76 |
-
def summarize_text(text,
|
77 |
-
|
78 |
-
|
79 |
|
80 |
# If the input language is not English, translate to English
|
81 |
-
if
|
82 |
-
text = translate_text(text,
|
83 |
|
84 |
# Summarize the text using mBART
|
85 |
inputs = multilingual_summarization_tokenizer(text, return_tensors='pt', padding=True, truncation=True)
|
86 |
summary_ids = multilingual_summarization_model.generate(inputs['input_ids'], num_beams=4, max_length=200, early_stopping=True)
|
87 |
summary = multilingual_summarization_tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
88 |
|
89 |
-
# Translate summary to the
|
90 |
-
if
|
91 |
-
summary = translate_text(summary, "en_XX",
|
92 |
|
93 |
return summary
|
94 |
|
95 |
# Streamlit interface
|
96 |
st.title("Multi-Language Text Summarization Tool")
|
|
|
97 |
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
|
102 |
if st.button("Summarize"):
|
103 |
-
if
|
104 |
-
summary = summarize_text(
|
105 |
-
st.
|
106 |
st.write(summary)
|
107 |
else:
|
108 |
-
st.warning("Please enter text to summarize.")
|
|
|
73 |
return translated_text
|
74 |
|
75 |
# Summarization function with multi-language support
|
76 |
+
def summarize_text(text, input_language="English", output_language="English"):
|
77 |
+
input_lang_code = LANGUAGES[input_language]
|
78 |
+
output_lang_code = LANGUAGES[output_language]
|
79 |
|
80 |
# If the input language is not English, translate to English
|
81 |
+
if input_lang_code != "en_XX":
|
82 |
+
text = translate_text(text, input_lang_code, "en_XX")
|
83 |
|
84 |
# Summarize the text using mBART
|
85 |
inputs = multilingual_summarization_tokenizer(text, return_tensors='pt', padding=True, truncation=True)
|
86 |
summary_ids = multilingual_summarization_model.generate(inputs['input_ids'], num_beams=4, max_length=200, early_stopping=True)
|
87 |
summary = multilingual_summarization_tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
88 |
|
89 |
+
# Translate summary to the output language if needed
|
90 |
+
if output_lang_code != "en_XX":
|
91 |
+
summary = translate_text(summary, "en_XX", output_lang_code)
|
92 |
|
93 |
return summary
|
94 |
|
95 |
# Streamlit interface
|
96 |
st.title("Multi-Language Text Summarization Tool")
|
97 |
+
st.write("Enter the text you want to summarize, select the input language, and choose the output language for the summary.")
|
98 |
|
99 |
+
text_input = st.text_area("Input Text")
|
100 |
+
input_language = st.selectbox("Input Language", options=list(LANGUAGES.keys()), index=list(LANGUAGES.keys()).index("English"))
|
101 |
+
output_language = st.selectbox("Output Language", options=list(LANGUAGES.keys()), index=list(LANGUAGES.keys()).index("English"))
|
102 |
|
103 |
if st.button("Summarize"):
|
104 |
+
if text_input:
|
105 |
+
summary = summarize_text(text_input, input_language, output_language)
|
106 |
+
st.write("Summary:")
|
107 |
st.write(summary)
|
108 |
else:
|
109 |
+
st.warning("Please enter some text to summarize.")
|