Update app.py
Browse files
app.py
CHANGED
|
@@ -1,71 +1,68 @@
|
|
| 1 |
-
from sumy.parsers.plaintext import PlaintextParser
|
| 2 |
-
from sumy.nlp.tokenizers import Tokenizer
|
| 3 |
-
from sumy.summarizers.text_rank import TextRankSummarizer
|
| 4 |
-
from sumy.
|
| 5 |
-
from sumy.
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
return
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
gr.themes.GoogleFont('
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
nltk.download('punkt', quiet=True)
|
| 70 |
-
nltk.download('punkt_tab', quiet=True)
|
| 71 |
-
app.queue(default_concurrency_limit=25).launch(show_api=True, max_threads=500, ssr_mode=False)
|
|
|
|
| 1 |
+
from sumy.parsers.plaintext import PlaintextParser
|
| 2 |
+
from sumy.nlp.tokenizers import Tokenizer
|
| 3 |
+
from sumy.summarizers.text_rank import TextRankSummarizer
|
| 4 |
+
from sumy.nlp.stemmers import Stemmer
|
| 5 |
+
from sumy.utils import get_stop_words
|
| 6 |
+
import gradio as gr
|
| 7 |
+
import nltk
|
| 8 |
+
import time
|
| 9 |
+
|
| 10 |
+
def textrank_summarizer(text_corpus):
|
| 11 |
+
start_time = time.time()
|
| 12 |
+
parser = PlaintextParser.from_string(text_corpus, Tokenizer("english"))
|
| 13 |
+
stemmer = Stemmer("english")
|
| 14 |
+
summarizer = TextRankSummarizer(stemmer)
|
| 15 |
+
summarizer.stop_words = get_stop_words("english")
|
| 16 |
+
sentences = summarizer(parser.document, 10)
|
| 17 |
+
summary = ""
|
| 18 |
+
for sentence in sentences:
|
| 19 |
+
summary += str(sentence) + ""
|
| 20 |
+
end_time = time.time()
|
| 21 |
+
print(f"Time taken: {end_time - start_time:.2f} seconds")
|
| 22 |
+
return summary
|
| 23 |
+
|
| 24 |
+
def clear_everything(text_corpus, summary):
|
| 25 |
+
return None, None
|
| 26 |
+
|
| 27 |
+
theme = gr.themes.Soft(
|
| 28 |
+
primary_hue="purple",
|
| 29 |
+
secondary_hue="cyan",
|
| 30 |
+
neutral_hue="slate",
|
| 31 |
+
font=[
|
| 32 |
+
gr.themes.GoogleFont('Syne'),
|
| 33 |
+
gr.themes.GoogleFont('Poppins'),
|
| 34 |
+
gr.themes.GoogleFont('Poppins'),
|
| 35 |
+
gr.themes.GoogleFont('Poppins')
|
| 36 |
+
],
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
with gr.Blocks(theme=theme, title="TextRank Summarizer", fill_height=True) as app:
|
| 40 |
+
gr.HTML(
|
| 41 |
+
value ='''
|
| 42 |
+
<h1 style="text-align: center;">TextRank Summarizer</h1>
|
| 43 |
+
<p style="text-align: center;">This app uses a TextRank approach to summarize PDF documents based on CPU.</p>
|
| 44 |
+
<p style="text-align: center;">The summarization process can take some time depending on the size of the text corpus and the complexity of the content.</p>
|
| 45 |
+
''')
|
| 46 |
+
with gr.Row():
|
| 47 |
+
with gr.Column():
|
| 48 |
+
text_corpus = gr.TextArea(label="Text Corpus", placeholder="Paste the text corpus here", lines=5)
|
| 49 |
+
with gr.Row():
|
| 50 |
+
clear_btn = gr.Button(value="Clear", variant='stop')
|
| 51 |
+
summarize_btn = gr.Button(value="Summarize", variant='primary')
|
| 52 |
+
summary = gr.TextArea(label="Raw Data", placeholder="The generated raw data will be displayed here", lines=7, interactive=False, show_copy_button=True)
|
| 53 |
+
|
| 54 |
+
summarize_btn.click(
|
| 55 |
+
textrank_summarizer,
|
| 56 |
+
inputs=[text_corpus],
|
| 57 |
+
outputs=[summary],
|
| 58 |
+
concurrency_limit=25,
|
| 59 |
+
scroll_to_output=True,
|
| 60 |
+
show_api=True,
|
| 61 |
+
api_name="textrank_summarizer",
|
| 62 |
+
show_progress="full",
|
| 63 |
+
)
|
| 64 |
+
clear_btn.click(clear_everything, inputs=[text_corpus, summary], outputs=[text_corpus, summary], show_api=False)
|
| 65 |
+
|
| 66 |
+
nltk.download('punkt', quiet=True)
|
| 67 |
+
nltk.download('punkt_tab', quiet=True)
|
| 68 |
+
app.queue(default_concurrency_limit=25).launch(show_api=True, max_threads=500, ssr_mode=False)
|
|
|
|
|
|
|
|
|