Spaces:
Runtime error
Runtime error
Commit ·
82cf5bb
1
Parent(s): b249f7c
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,46 +0,0 @@
|
|
| 1 |
-
from newspaper import Article
|
| 2 |
-
from newspaper import Config
|
| 3 |
-
import nltk
|
| 4 |
-
nltk.download('punkt')
|
| 5 |
-
|
| 6 |
-
from transformers import pipeline
|
| 7 |
-
import gradio as gr
|
| 8 |
-
from gradio.mix import Parallel, Series
|
| 9 |
-
|
| 10 |
-
def extract_article_text(url):
|
| 11 |
-
USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Firefox/78.0'
|
| 12 |
-
config = Config()
|
| 13 |
-
config.browser_user_agent = USER_AGENT
|
| 14 |
-
config.request_timeout = 10
|
| 15 |
-
|
| 16 |
-
article = Article(url, config=config)
|
| 17 |
-
article.download()
|
| 18 |
-
article.parse()
|
| 19 |
-
text = article.text
|
| 20 |
-
return text
|
| 21 |
-
|
| 22 |
-
extractor = gr.Interface(extract_article_text, 'text', 'text')
|
| 23 |
-
summarizer = gr.Interface.load("huggingface/facebook/bart-large-cnn")
|
| 24 |
-
|
| 25 |
-
sample_url = [['https://parstoday.com/en/news/iran-i163822-iran_condemns_terrorist_attack_in_pakistan_reaffirms_need_to_fight_terrorism_across_region/'],
|
| 26 |
-
['https://parstoday.com/en/news/west_asia-i163734-ansarullah_yemenis_entitled_to_avenge_nation%E2%80%99s_sufferings_inflicted_due_to_war_siege/'],
|
| 27 |
-
['https://parstoday.com/en/news/west_asia-i163684-saudi_led_warplanes_intensify_airstrikes_against_yemeni_capital/']]
|
| 28 |
-
|
| 29 |
-
desc = '''
|
| 30 |
-
Let Hugging Face models summarize articles for you.
|
| 31 |
-
Note: Shorter articles generate faster summaries.
|
| 32 |
-
This summarizer uses bart-large-cnn model by Facebook
|
| 33 |
-
'''
|
| 34 |
-
|
| 35 |
-
iface = Series(extractor, summarizer,
|
| 36 |
-
inputs = gr.inputs.Textbox(
|
| 37 |
-
lines = 2,
|
| 38 |
-
label = 'URL'
|
| 39 |
-
),
|
| 40 |
-
outputs = 'text',
|
| 41 |
-
title = 'News Summarizer',
|
| 42 |
-
theme = 'huggingface',
|
| 43 |
-
description = desc,
|
| 44 |
-
examples=sample_url)
|
| 45 |
-
|
| 46 |
-
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|