ganeshkamath89 commited on
Commit
cb38464
1 Parent(s): f932059

Trying out a different code to get Wikipedia Summary

Browse files
Files changed (1) hide show
  1. app.py +23 -27
app.py CHANGED
@@ -4,34 +4,30 @@ import wikipediaapi
4
  import nltk
5
  nltk.download('punkt')
6
 
7
- def extract_article_summary(url):
8
- wiki_wiki = wikipediaapi.Wikipedia('MyProjectName (merlin@example.com)', 'en')
9
- page_py = wiki_wiki.page("{url}_(programming_language)")
10
- text = page_py.summary[0:60]
11
- summarizer = pipeline("summarization", model = "facebook/bart-large-cnn")
12
- return summarizer(text)[0]['summary_text']
13
 
14
- sample_url = [['C++'],
15
- ['Java'],
16
- ['Matlab']]
17
 
18
- desc = '''
19
- Let Hugging Face models summarize Wikipedia Programing Language articles for you.
20
- Note: Shorter articles generate faster summaries.
21
- This summarizer uses bart-large-cnn model by Facebook
22
- '''
23
 
24
- demo = gr.Interface (
25
- extract_article_summary,
26
- inputs = gr.Textbox(
27
- lines = 2,
28
- label = 'URL'
29
- ),
30
- outputs = 'text',
31
- title = 'Wikipedia Programming Language Summarizer',
32
- theme = 'huggingface',
33
- description = desc,
34
- examples=sample_url
35
- )
36
 
37
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
4
  import nltk
5
  nltk.download('punkt')
6
 
7
+ def get_wiki_summary(search):
8
+ wiki_wiki = wikipediaapi.Wikipedia('en')
9
+ page = wiki_wiki.page(search)
 
 
 
10
 
11
+ isExist = page.exists()
12
+ if not isExist:
13
+ return isExist, "Not found", "Not found", "Not found", "Not found"
14
 
15
+ url = page.fullurl
16
+ tittle = page.title
17
+ summary = page.summary[0:60]
18
+ text = page.text
 
19
 
20
+ return isExist, url, tittle, summary, text
 
 
 
 
 
 
 
 
 
 
 
21
 
22
+ wiki_summary = gr.Interface(
23
+ get_wiki_summary,
24
+ gr.Text(label="Search Wikipedia"),
25
+ [
26
+ gr.Text(label="Page exists?"),
27
+ gr.Text(label="URL"),
28
+ gr.Text(label="Title"),
29
+ gr.Text(label="Summary"),
30
+ gr.Text(label="Text")
31
+ ]
32
+ )
33
+ wiki_summary.launch()