benthecoder commited on
Commit
1eb87da
1 Parent(s): 8aa8254

initial commit

Browse files
Files changed (2) hide show
  1. main.py +47 -0
  2. requirements.txt +4 -0
main.py ADDED
@@ -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
+
11
+ def extract_article_text(url):
12
+ USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Firefox/78.0'
13
+ config = Config()
14
+ config.browser_user_agent = USER_AGENT
15
+ config.request_timeout = 10
16
+
17
+ article = Article(url, config=config)
18
+ article.download()
19
+ article.parse()
20
+ text = article.text
21
+ return text
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://www.technologyreview.com/2021/07/22/1029973/deepmind-alphafold-protein-folding-biology-disease-drugs-proteome/'],
27
+ ['https://www.technologyreview.com/2021/07/21/1029860/disability-rights-employment-discrimination-ai-hiring/'],
28
+ ['https://www.technologyreview.com/2021/07/09/1028140/ai-voice-actors-sound-human/']]
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()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio==2.4.2
2
+ newspaper==0.1.0.7
3
+ nltk==3.6.5
4
+ transformers==4.12.3