Spaces:
Build error
Build error
| import streamlit as st | |
| from transformers import pipeline | |
| from newspaper import Article | |
| # Load Summarization Model | |
| def load_summarizer(): | |
| return pipeline("summarization", model="facebook/bart-large-cnn") | |
| summarizer = load_summarizer() | |
| # Streamlit UI | |
| st.title("📰 Real-Time Content Summarizer") | |
| st.write("Paste a URL or enter text to get a summary!") | |
| # Input option | |
| option = st.radio("Choose input type:", ("URL", "Manual Text")) | |
| if option == "URL": | |
| url = st.text_input("Enter the article URL:") | |
| if st.button("Summarize") and url: | |
| try: | |
| article = Article(url) | |
| article.download() | |
| article.parse() | |
| text = article.text | |
| summary = summarizer(text, max_length=150, min_length=50, do_sample=False)[0]['summary_text'] | |
| st.subheader("Summary:") | |
| st.write(summary) | |
| except Exception as e: | |
| st.error("Error fetching the article. Please check the URL.") | |
| elif option == "Manual Text": | |
| text_input = st.text_area("Enter text to summarize:") | |
| if st.button("Summarize") and text_input: | |
| summary = summarizer(text_input, max_length=150, min_length=50, do_sample=False)[0]['summary_text'] | |
| st.subheader("Summary:") | |
| st.write(summary) | |
| st.write("Made with ❤️ using Streamlit & Hugging Face Transformers") | |