Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,40 +1,21 @@
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
-
from nltk.tokenize import sent_tokenize
|
4 |
-
pip install nltk
|
5 |
|
6 |
-
|
7 |
-
summarizer_abstractive = pipeline("summarization", model="facebook/bart-large-cnn")
|
8 |
-
summarizer_extractive = pipeline("summarization", model="bert-extractive-summarizer")
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
sentences = sent_tokenize(text)
|
14 |
-
if model_type == "Abstractive":
|
15 |
-
# Process using the abstractive model (BART)
|
16 |
-
summary = summarizer_abstractive(text, max_length=max_length, min_length=min_length, do_sample=False)
|
17 |
-
return summary[0]['summary_text']
|
18 |
-
|
19 |
-
elif model_type == "Extractive":
|
20 |
-
# Process using the extractive model (BERT)
|
21 |
-
summary = summarizer_extractive(text)
|
22 |
-
return ' '.join([sentence['sentence'] for sentence in summary])
|
23 |
|
24 |
-
# Create Gradio Interface
|
25 |
demo = gr.Interface(
|
26 |
fn=summarize_text,
|
27 |
-
inputs=
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
gr.Slider(minimum=10, maximum=150, step=5, label="Min Length", value=50),
|
32 |
-
],
|
33 |
-
outputs="text",
|
34 |
-
title="Advanced Text Summarizer",
|
35 |
-
description="This tool provides both abstractive and extractive summarization options, allowing you to select the best method and adjust summary length.",
|
36 |
-
live=True,
|
37 |
)
|
38 |
|
39 |
-
# Launch the interface
|
40 |
demo.launch()
|
|
|
1 |
+
!pip install transformers
|
2 |
+
!pip install gradio
|
3 |
+
|
4 |
import gradio as gr
|
5 |
from transformers import pipeline
|
|
|
|
|
6 |
|
7 |
+
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
|
|
|
|
8 |
|
9 |
+
def summarize_text(text):
|
10 |
+
summary = summarizer(text, max_length=200, min_length=100, do_sample=False)
|
11 |
+
return summary[0]['summary_text']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
|
|
13 |
demo = gr.Interface(
|
14 |
fn=summarize_text,
|
15 |
+
inputs=gr.Textbox(placeholder="Enter your text here", label="Input Text"),
|
16 |
+
outputs=gr.Textbox(label="Summary"),
|
17 |
+
title="Text Summarizer",
|
18 |
+
description="This chatbot takes a long text as input and returns a summary."
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
)
|
20 |
|
|
|
21 |
demo.launch()
|