Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
from newspaper import Article
|
3 |
+
from newspaper import Config
|
4 |
+
import gradio as gr
|
5 |
+
from gradio.mix import Parallel, Series
|
6 |
+
|
7 |
+
def extrac_text(url):
|
8 |
+
USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Firefox/78.0'
|
9 |
+
config = Config()
|
10 |
+
config.browser_user_agent = USER_AGENT
|
11 |
+
config.request_timeout = 10
|
12 |
+
|
13 |
+
article = Article(url, config=config)
|
14 |
+
article.download()
|
15 |
+
article.parse()
|
16 |
+
text = article.text
|
17 |
+
return text
|
18 |
+
|
19 |
+
extractor = gr.Interface(extrac_text, 'text', 'text')
|
20 |
+
summarizer = gr.Interface.load("mmcquade11/autonlp-reuters-summarization-34018133")
|
21 |
+
sample_url = [['https://www.cp24.com/news/ontario-reports-481-new-covid-19-cases-1-death-1.5667950'],
|
22 |
+
]
|
23 |
+
desc = '''
|
24 |
+
The news summarizer app uses an AutoNLP model trained on the Reuters dataset.
|
25 |
+
'''
|
26 |
+
iface = Series(extractor, summarizer,
|
27 |
+
inputs = gr.inputs.Textbox(
|
28 |
+
lines = 2,
|
29 |
+
label = 'Enter URL below'
|
30 |
+
),
|
31 |
+
outputs = 'text',
|
32 |
+
title = 'News Summarizer',
|
33 |
+
theme = 'grass',
|
34 |
+
layout = 'horizontal',
|
35 |
+
description = desc,
|
36 |
+
examples=sample_url)
|
37 |
+
iface.launch()
|