Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| from transformers import pipeline | |
| # Load the summarization pipeline | |
| def load_summarizer(): | |
| return pipeline("summarization", model="facebook/bart-large-cnn") | |
| summarizer = load_summarizer() | |
| # Streamlit app title and description | |
| st.title("Text Summarization with BART") | |
| st.write("Enter the text you want to summarize below:") | |
| # Text input | |
| text = st.text_area("Input Text", height=300) | |
| # Summarization parameters | |
| st.sidebar.header("Summarization Parameters") | |
| max_length = st.sidebar.slider("Max Length", 50, 500, 150, 10) | |
| min_length = st.sidebar.slider("Min Length", 10, 100, 50, 5) | |
| do_sample = st.sidebar.checkbox("Use Sampling", value=False) | |
| # Summarize button | |
| if st.button("Summarize"): | |
| if text: | |
| with st.spinner("Summarizing..."): | |
| try: | |
| summary = summarizer( | |
| text, | |
| max_length=max_length, | |
| min_length=min_length, | |
| do_sample=do_sample, | |
| ) | |
| st.subheader("Summary:") | |
| st.write(summary[0]["summary_text"]) | |
| except Exception as e: | |
| st.error(f"An error occurred: {e}") | |
| else: | |
| st.warning("Please input text to summarize.") | |