Dannyar608 commited on
Commit
ccbb8fd
·
verified ·
1 Parent(s): cabfb2c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -30
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
- # Initialize the summarizer pipelines (abstractive and extractive)
7
- summarizer_abstractive = pipeline("summarization", model="facebook/bart-large-cnn")
8
- summarizer_extractive = pipeline("summarization", model="bert-extractive-summarizer")
9
 
10
- # Function to summarize text using the selected model
11
- def summarize_text(text, model_type="Abstractive", max_length=150, min_length=50):
12
- # Tokenize the text into sentences
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
- gr.Textbox(placeholder="Enter your long text here", label="Input Text", lines=10),
29
- gr.Radio(choices=["Abstractive", "Extractive"], label="Summarization Method", value="Abstractive"),
30
- gr.Slider(minimum=50, maximum=500, step=10, label="Max Length", value=150),
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()