vinni1484 commited on
Commit
a1aeba3
·
1 Parent(s): 14ca929

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -12
app.py CHANGED
@@ -1,16 +1,32 @@
1
  import gradio as gr
2
- import transformers
3
- from transformers import BartTokenizer, BartForConditionalGeneration
 
4
 
5
- model_name = 'facebook/bart-large-cnn'
6
- tokenizer = BartTokenizer.from_pretrained(model_name)
7
- model = BartForConditionalGeneration.from_pretrained(model_name)
8
 
9
- def summarize(inp):
10
- inp = inp.replace('\n','')
11
- inp = tokenizer.encode(inp, return_tensors='pt', max_length=1024)
12
- summary_ids = model.generate(inp, num_beams=4, min_length=200, max_length=300, early_stopping=True)
13
- summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
14
- return summary
15
 
16
- gr.Interface(fn=summarize, inputs=gr.inputs.Textbox(lines=7, label="Input Text"), outputs="text").launch(inline=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from gradio.mix import Parallel, Series
3
+ from transformers import pipeline
4
+ import wikipedia
5
 
6
+ def extract_article_text(url):
7
+ data = wikipedia.page(pageid=url).content
8
+ return text
9
 
10
+ extractor = gr.Interface(extract_article_text, 'text', 'text')
11
+ summarizer = gr.Interface.load("huggingface/facebook/bart-large-cnn")
 
 
 
 
12
 
13
+ sample_url = [[1691376],[45199431]]
14
+
15
+ description = '''
16
+ This application summarizes a news article based on the sentences used in the article.
17
+ Enter a news article link and submit for a summary.
18
+ A shorter news article produces a faster summary. A news article behind a paywall may produce an error.
19
+ '''
20
+
21
+ iface = Series(extractor, summarizer,
22
+ inputs = gr.inputs.Textbox(
23
+ lines = 2,
24
+ label = 'URL'
25
+ ),
26
+ outputs = 'text',
27
+ title = 'Extractive News Summarizer BART',
28
+ theme = 'grass',
29
+ description = description,
30
+ examples=sample_url)
31
+
32
+ iface.launch()