Spaces:
Runtime error
Runtime error
Update extractive_model.py
Browse files- extractive_model.py +28 -0
extractive_model.py
CHANGED
@@ -44,3 +44,31 @@ def summarize_with_textrank(text, sentences_count=5):
|
|
44 |
summary_text = "\n".join(str(sentence) for sentence in text_rank_summary)
|
45 |
|
46 |
return summary_text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
summary_text = "\n".join(str(sentence) for sentence in text_rank_summary)
|
45 |
|
46 |
return summary_text
|
47 |
+
|
48 |
+
|
49 |
+
# Define LSA summarization function
|
50 |
+
def summarize_with_lsa(text, sentences_count=5):
|
51 |
+
"""
|
52 |
+
Summarizes the provided text using LSA (Latent Semantic Analysis) algorithm.
|
53 |
+
Args:
|
54 |
+
text (str): Text to summarize.
|
55 |
+
sentences_count (int): Number of sentences for the summary.
|
56 |
+
Returns:
|
57 |
+
str: Summarized text.
|
58 |
+
"""
|
59 |
+
|
60 |
+
# Check if the text is not empty
|
61 |
+
if not text.strip():
|
62 |
+
return "Provided text is empty."
|
63 |
+
|
64 |
+
# Create a parser for the provided text
|
65 |
+
parser = PlaintextParser.from_string(text, Tokenizer("english"))
|
66 |
+
|
67 |
+
# Use LSA for summarization
|
68 |
+
lsa_summarizer = LsaSummarizer()
|
69 |
+
lsa_summary = lsa_summarizer(parser.document, sentences_count=sentences_count)
|
70 |
+
|
71 |
+
# Compile summary into a single string
|
72 |
+
summary_text = "\n".join(str(sentence) for sentence in lsa_summary)
|
73 |
+
|
74 |
+
return summary_text
|