Spaces:
Build error
Build error
Commit ·
78e946b
1
Parent(s): 4ed8022
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from newspaper import Article
|
| 2 |
+
from newspaper import Config
|
| 3 |
+
import nltk
|
| 4 |
+
nltk.download('punkt')
|
| 5 |
+
from gradio.mix import Series
|
| 6 |
+
import gradio as gr
|
| 7 |
+
def extract_article_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 |
+
extractor = gr.Interface(extract_article_text, 'text', 'text')
|
| 19 |
+
summarizer = gr.Interface.load("huggingface/facebook/bart-large-cnn")
|
| 20 |
+
|
| 21 |
+
sample_url = [['https://www.technologyreview.com/2021/07/22/1029973/deepmind-alphafold-protein-folding-biology-disease-drugs-proteome/'],
|
| 22 |
+
['https://www.technologyreview.com/2021/07/21/1029860/disability-rights-employment-discrimination-ai-hiring/'],
|
| 23 |
+
['https://www.technologyreview.com/2021/07/09/1028140/ai-voice-actors-sound-human/']]
|
| 24 |
+
|
| 25 |
+
desc = '''
|
| 26 |
+
Generate summary of an article using bart-large-cnn model by Facebook.
|
| 27 |
+
'''
|
| 28 |
+
|
| 29 |
+
iface = Series(extractor, summarizer,
|
| 30 |
+
inputs = gr.inputs.Textbox(
|
| 31 |
+
lines = 2,
|
| 32 |
+
label = 'URL'
|
| 33 |
+
),
|
| 34 |
+
outputs = 'text',
|
| 35 |
+
title = 'Article Cortex: Transformers powered article summarization engine',
|
| 36 |
+
theme = 'huggingface',
|
| 37 |
+
description = desc,
|
| 38 |
+
examples=sample_url,allow_flagging="manual",flagging_options=["random summary", "useful summary"])
|
| 39 |
+
|
| 40 |
+
iface.launch(share=True, debug=True)
|