Commit
·
8a890e9
1
Parent(s):
d4fbf5c
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import spacy
|
2 |
+
import streamlit as st
|
3 |
+
|
4 |
+
def article_summarizer(article_text, num_sentences=3):
|
5 |
+
nlp = spacy.load("en_core_web_sm")
|
6 |
+
doc = nlp(article_text)
|
7 |
+
sentence_importance = {}
|
8 |
+
for sentence in doc.sents:
|
9 |
+
sentence_tokens = [token for token in sentence if not token.is_stop]
|
10 |
+
sentence_rank = sum(token.rank for token in sentence_tokens)
|
11 |
+
sentence_importance[sentence] = sentence_rank
|
12 |
+
sorted_sentences = sorted(sentence_importance, key=lambda x: sentence_importance[x], reverse=True)
|
13 |
+
summary = " ".join(str(sentence) for sentence in sorted_sentences[:num_sentences])
|
14 |
+
return summary
|
15 |
+
|
16 |
+
st.title("Article Summarizer")
|
17 |
+
|
18 |
+
article = st.text_area("Enter your article here:")
|
19 |
+
num_sentences = st.slider("Select the number of sentences for the summary:", 1, 10, 3)
|
20 |
+
|
21 |
+
if st.button("Summarize"):
|
22 |
+
if article:
|
23 |
+
summary = article_summarizer(article, num_sentences)
|
24 |
+
st.subheader("Summary:")
|
25 |
+
st.write(summary)
|
26 |
+
else:
|
27 |
+
st.warning("Please enter an article to summarize.")
|