Spaces:
Sleeping
Sleeping
File size: 1,281 Bytes
64b7f01 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
import streamlit as st
from transformers import pipeline
# Load summarization model
@st.cache_resource
def load_summarizer():
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
return summarizer
# Summarize input text
def summarize_text(input_text, max_length=130, min_length=30):
summarizer = load_summarizer()
summary = summarizer(input_text, max_length=max_length, min_length=min_length, do_sample=False)
return summary[0]['summary_text']
# Streamlit app interface
def main():
st.title("Text Summarization App")
# Input box for text to summarize
input_text = st.text_area("Enter the text you want to summarize:", "Paste your article or text here...")
# Slider for max and min length of the summary
max_length = st.slider("Maximum length of summary:", min_value=50, max_value=300, value=130)
min_length = st.slider("Minimum length of summary:", min_value=20, max_value=100, value=30)
# Button to summarize
if st.button("Summarize"):
with st.spinner("Summarizing..."):
summary = summarize_text(input_text, max_length=max_length, min_length=min_length)
st.subheader("Summary")
st.write(summary)
# Run the app
if __name__ == '__main__':
main()
|