kazimsayed commited on
Commit
c842ef9
1 Parent(s): ab8d8a1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py CHANGED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
23
+ extractor = gr.Interface(extract_article_text, 'text', 'text')
24
+ summarizer = gr.Interface.load("huggingface/facebook/bart-large-cnn")
25
+
26
+ sample_url = [['https://parstoday.com/en/news/iran-i163822-iran_condemns_terrorist_attack_in_pakistan_reaffirms_need_to_fight_terrorism_across_region/'],
27
+ ['https://parstoday.com/en/news/west_asia-i163734-ansarullah_yemenis_entitled_to_avenge_nation%E2%80%99s_sufferings_inflicted_due_to_war_siege/'],
28
+ ['https://parstoday.com/en/news/west_asia-i163684-saudi_led_warplanes_intensify_airstrikes_against_yemeni_capital/']]
29
+
30
+ desc = '''
31
+ Let Hugging Face models summarize articles for you.
32
+ Note: Shorter articles generate faster summaries.
33
+ This summarizer uses bart-large-cnn model by Facebook
34
+ '''
35
+
36
+ iface = Series(extractor, summarizer,
37
+ inputs = gr.inputs.Textbox(
38
+ lines = 2,
39
+ label = 'URL'
40
+ ),
41
+ outputs = 'text',
42
+ title = 'News Summarizer',
43
+ theme = 'huggingface',
44
+ description = desc,
45
+ examples=sample_url)
46
+
47
+ iface.launch()