Spaces:
Runtime error
Runtime error
Adding pretty print and replacing wikipedia article URLs with news URLs
Browse files
app.py
CHANGED
|
@@ -2,40 +2,47 @@ from newspaper import Article, Config
|
|
| 2 |
from transformers import pipeline
|
| 3 |
import gradio as gr
|
| 4 |
|
|
|
|
| 5 |
def extract_article_summary(url):
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
Let Hugging Face models summarize articles for you.
|
| 24 |
Note: Shorter articles generate faster summaries.
|
| 25 |
This summarizer uses bart-large-cnn model by Facebook
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
demo = gr.Interface
|
| 29 |
-
extract_article_summary,
|
| 30 |
-
inputs
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
theme = 'huggingface',
|
| 37 |
-
description = desc,
|
| 38 |
-
examples=sample_url
|
| 39 |
)
|
| 40 |
|
| 41 |
-
demo.launch()
|
|
|
|
| 2 |
from transformers import pipeline
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
+
|
| 6 |
def extract_article_summary(url):
|
| 7 |
+
USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Firefox/78.0"
|
| 8 |
+
config = Config()
|
| 9 |
+
config.browser_user_agent = USER_AGENT
|
| 10 |
+
config.request_timeout = 10
|
| 11 |
+
|
| 12 |
+
article = Article(url, config=config)
|
| 13 |
+
article.download()
|
| 14 |
+
article.parse()
|
| 15 |
+
text = article.text
|
| 16 |
+
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 17 |
+
return summarizer(text)[0]["summary_text"]
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
sample_url = [
|
| 21 |
+
[
|
| 22 |
+
"https://www.technologyreview.com/2021/07/22/1029973/deepmind-alphafold-protein-folding-biology-disease-drugs-proteome/"
|
| 23 |
+
],
|
| 24 |
+
[
|
| 25 |
+
"https://www.technologyreview.com/2021/07/21/1029860/disability-rights-employment-discrimination-ai-hiring/"
|
| 26 |
+
],
|
| 27 |
+
[
|
| 28 |
+
"https://www.technologyreview.com/2021/07/09/1028140/ai-voice-actors-sound-human/"
|
| 29 |
+
],
|
| 30 |
+
]
|
| 31 |
+
|
| 32 |
+
desc = """
|
| 33 |
Let Hugging Face models summarize articles for you.
|
| 34 |
Note: Shorter articles generate faster summaries.
|
| 35 |
This summarizer uses bart-large-cnn model by Facebook
|
| 36 |
+
"""
|
| 37 |
+
|
| 38 |
+
demo = gr.Interface(
|
| 39 |
+
extract_article_summary,
|
| 40 |
+
inputs=gr.Textbox(lines=2, label="URL"),
|
| 41 |
+
outputs="text",
|
| 42 |
+
title="News Summarizer",
|
| 43 |
+
theme="huggingface",
|
| 44 |
+
description=desc,
|
| 45 |
+
examples=sample_url,
|
|
|
|
|
|
|
|
|
|
| 46 |
)
|
| 47 |
|
| 48 |
+
demo.launch()
|