Spaces:
Build error
Build error
init
Browse files
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import T5ForConditionalGeneration, T5Tokenizer
|
| 3 |
+
|
| 4 |
+
# Load the model and tokenizer
|
| 5 |
+
model_name = 'utrobinmv/t5_summary_en_ru_zh_base_2048'
|
| 6 |
+
model = T5ForConditionalGeneration.from_pretrained(model_name)
|
| 7 |
+
tokenizer = T5Tokenizer.from_pretrained(model_name)
|
| 8 |
+
|
| 9 |
+
def summarize_text(text, prefix):
|
| 10 |
+
src_text = prefix + text
|
| 11 |
+
input_ids = tokenizer(src_text, return_tensors="pt")
|
| 12 |
+
generated_tokens = model.generate(**input_ids)
|
| 13 |
+
result = tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)
|
| 14 |
+
return result[0]
|
| 15 |
+
|
| 16 |
+
st.title('Text Summarization App')
|
| 17 |
+
|
| 18 |
+
input_text = st.text_area("Enter the text to summarize:", height=300)
|
| 19 |
+
|
| 20 |
+
if st.button("Generate Summaries"):
|
| 21 |
+
if input_text:
|
| 22 |
+
title1 = summarize_text(input_text, 'summary: ')
|
| 23 |
+
title2 = summarize_text(input_text, 'summary brief: ')
|
| 24 |
+
st.write("### Title 1")
|
| 25 |
+
st.write(title1)
|
| 26 |
+
st.write("### Title 2")
|
| 27 |
+
st.write(title2)
|
| 28 |
+
else:
|
| 29 |
+
st.warning("Please enter some text to summarize.")
|