Spaces:
Sleeping
Sleeping
import streamlit as st | |
from transformers import pipeline | |
# Load summarization model | |
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() | |