Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,4 +5,82 @@ nltk.download('punkt')
|
|
| 5 |
|
| 6 |
from transformers import pipeline
|
| 7 |
import gradio as gr
|
| 8 |
-
from gradio.mix import Parallel, Series
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
from transformers import pipeline
|
| 7 |
import gradio as gr
|
| 8 |
+
from gradio.mix import Parallel, Series
|
| 9 |
+
USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Firefox/78.0'
|
| 10 |
+
|
| 11 |
+
config = Config()
|
| 12 |
+
config.browser_user_agent = USER_AGENT
|
| 13 |
+
config.request_timeout = 10
|
| 14 |
+
|
| 15 |
+
url = 'https://www.technologyreview.com/2021/07/09/1028140/ai-voice-actors-sound-human/'
|
| 16 |
+
article = Article(url, config=config)
|
| 17 |
+
article.download()
|
| 18 |
+
article.parse()
|
| 19 |
+
|
| 20 |
+
authors = ", ".join(author for author in article.authors)
|
| 21 |
+
title = article.title
|
| 22 |
+
date = article.publish_date
|
| 23 |
+
text = article.text
|
| 24 |
+
image = article.top_image
|
| 25 |
+
videos = article.movies
|
| 26 |
+
url = article.url
|
| 27 |
+
print("Information about the article")
|
| 28 |
+
print("=" * 30)
|
| 29 |
+
print(f"Title: {title}")
|
| 30 |
+
print(f"Author(s): {authors}")
|
| 31 |
+
print(f"Publish date: {date}")
|
| 32 |
+
print(f"Image: {image}")
|
| 33 |
+
print(f"Videos: {videos}")
|
| 34 |
+
print(f"Article link: {url}")
|
| 35 |
+
print(f"Content: {text[:100] + '...'}")
|
| 36 |
+
article.nlp()
|
| 37 |
+
keywords = article.keywords
|
| 38 |
+
keywords.sort()
|
| 39 |
+
print(keywords)
|
| 40 |
+
print(f"Summary: \n{article.summary}")
|
| 41 |
+
io1 = gr.Interface.load('huggingface/sshleifer/distilbart-cnn-12-6')
|
| 42 |
+
io2 = gr.Interface.load("huggingface/facebook/bart-large-cnn")
|
| 43 |
+
io3 = gr.Interface.load("huggingface/google/pegasus-xsum")
|
| 44 |
+
io4 = gr.Interface.load("huggingface/sshleifer/distilbart-cnn-6-6")
|
| 45 |
+
|
| 46 |
+
iface = Parallel(io1, io2, io3, io4,
|
| 47 |
+
theme='huggingface',
|
| 48 |
+
inputs = gr.inputs.Textbox(lines = 10, label="Text"))
|
| 49 |
+
|
| 50 |
+
iface.launch()
|
| 51 |
+
def extract_article_text(url):
|
| 52 |
+
USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Firefox/78.0'
|
| 53 |
+
config = Config()
|
| 54 |
+
config.browser_user_agent = USER_AGENT
|
| 55 |
+
config.request_timeout = 10
|
| 56 |
+
|
| 57 |
+
article = Article(url, config=config)
|
| 58 |
+
article.download()
|
| 59 |
+
article.parse()
|
| 60 |
+
text = article.text
|
| 61 |
+
return text
|
| 62 |
+
extractor = gr.Interface(extract_article_text, 'text', 'text')
|
| 63 |
+
summarizer = gr.Interface.load("huggingface/facebook/bart-large-cnn")
|
| 64 |
+
|
| 65 |
+
sample_url = [['https://www.technologyreview.com/2021/07/22/1029973/deepmind-alphafold-protein-folding-biology-disease-drugs-proteome/'],
|
| 66 |
+
['https://www.technologyreview.com/2021/07/21/1029860/disability-rights-employment-discrimination-ai-hiring/'],
|
| 67 |
+
['https://www.technologyreview.com/2021/07/09/1028140/ai-voice-actors-sound-human/']]
|
| 68 |
+
|
| 69 |
+
desc = '''
|
| 70 |
+
Let Hugging Face models summarize articles for you.
|
| 71 |
+
Note: Shorter articles generate faster summaries.
|
| 72 |
+
This summarizer uses bart-large-cnn model by Facebook
|
| 73 |
+
'''
|
| 74 |
+
|
| 75 |
+
iface = Series(extractor, summarizer,
|
| 76 |
+
inputs = gr.inputs.Textbox(
|
| 77 |
+
lines = 2,
|
| 78 |
+
label = 'URL'
|
| 79 |
+
),
|
| 80 |
+
outputs = 'text',
|
| 81 |
+
title = 'News Summarizer',
|
| 82 |
+
theme = 'huggingface',
|
| 83 |
+
description = desc,
|
| 84 |
+
examples=sample_url)
|
| 85 |
+
|
| 86 |
+
iface.launch()
|