Spaces:
Build error
Build error
File size: 1,360 Bytes
844a982 |
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 40 41 |
import streamlit as st
from transformers import pipeline
from newspaper import Article
# Load Summarization Model
@st.cache_resource
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")
|