Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,16 +1,32 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
-
from transformers import
|
|
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
|
9 |
-
|
10 |
-
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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()
|