Commit
·
2e598b9
1
Parent(s):
9a6d2b3
Update app.py
Browse files
app.py
CHANGED
@@ -13,7 +13,7 @@ nltk.download('stopwords')
|
|
13 |
# Function to read and preprocess the article
|
14 |
def read_article(article):
|
15 |
sentences = nltk.sent_tokenize(article)
|
16 |
-
sentences = [sentence for sentence in sentences if len
|
17 |
return sentences
|
18 |
|
19 |
# Function to compute sentence similarity based on cosine similarity
|
@@ -43,7 +43,7 @@ def sentence_similarity(sent1, sent2, stopwords):
|
|
43 |
|
44 |
# Function to create a similarity matrix of sentences
|
45 |
def build_similarity_matrix(sentences, stopwords):
|
46 |
-
similarity_matrix = np.zeros((len(sentences), len(sentences))
|
47 |
|
48 |
for i in range(len(sentences)):
|
49 |
for j in range(len(sentences)):
|
@@ -66,7 +66,7 @@ def generate_summary(article, top_n=5):
|
|
66 |
scores = nx.pagerank(sentence_similarity_graph)
|
67 |
|
68 |
# Sort the sentences by score
|
69 |
-
ranked_sentences = sorted(((scores[i], sentence) for i, sentence in enumerate
|
70 |
|
71 |
# Get the top N sentences as the summary
|
72 |
summary = " ".join([sentence for _, sentence in ranked_sentences[:top_n]])
|
|
|
13 |
# Function to read and preprocess the article
|
14 |
def read_article(article):
|
15 |
sentences = nltk.sent_tokenize(article)
|
16 |
+
sentences = [sentence for sentence in sentences if len(sentence) > 10] # Filter out very short sentences
|
17 |
return sentences
|
18 |
|
19 |
# Function to compute sentence similarity based on cosine similarity
|
|
|
43 |
|
44 |
# Function to create a similarity matrix of sentences
|
45 |
def build_similarity_matrix(sentences, stopwords):
|
46 |
+
similarity_matrix = np.zeros((len(sentences), len(sentences)))
|
47 |
|
48 |
for i in range(len(sentences)):
|
49 |
for j in range(len(sentences)):
|
|
|
66 |
scores = nx.pagerank(sentence_similarity_graph)
|
67 |
|
68 |
# Sort the sentences by score
|
69 |
+
ranked_sentences = sorted(((scores[i], sentence) for i, sentence in enumerate sentences), reverse=True)
|
70 |
|
71 |
# Get the top N sentences as the summary
|
72 |
summary = " ".join([sentence for _, sentence in ranked_sentences[:top_n]])
|