Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| from transformers import pipeline | |
| # Load the summarization model from Hugging Face | |
| summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6", revision="a4f8f3e") | |
| # Streamlit app | |
| def main(): | |
| # Set the title and description of the app | |
| st.title("Text Summarizer App") | |
| st.write( | |
| "Enter a piece of text, select the length of the summary, and get a concise summary!" | |
| ) | |
| # Input text box for user input | |
| input_text = st.text_area("Enter your text here:") | |
| # Length selector for summary | |
| summary_length = st.slider("Select summary length:", min_value=50, max_value=500, value=150, step=50) | |
| # Check if the user has entered any text | |
| if st.button("Generate Summary"): | |
| if not input_text: | |
| st.warning("Please enter some text.") | |
| else: | |
| # Generate summary using the Hugging Face summarization model | |
| summary = summarizer(input_text, max_length=summary_length, min_length=50, length_penalty=2.0, num_beams=4) | |
| st.subheader("Summary:") | |
| st.write(summary[0]["summary_text"]) | |
| # Run the app | |
| if __name__ == "__main__": | |
| main() | |