Walid Aissa commited on
Commit
a381bc0
1 Parent(s): 9831428

wikipedia api to find the summary of the article related to top keyword

Browse files
Files changed (1) hide show
  1. app.py +17 -4
app.py CHANGED
@@ -1,5 +1,7 @@
1
  import os
2
  import gradio as gr
 
 
3
 
4
  from transformers import (
5
  TokenClassificationPipeline,
@@ -29,16 +31,27 @@ class KeyphraseExtractionPipeline(TokenClassificationPipeline):
29
  model_name = "ml6team/keyphrase-extraction-kbir-inspec"
30
  extractor = KeyphraseExtractionPipeline(model=model_name)
31
 
32
- # Inference
33
- def keyphrases_out(input):
34
  input = input.replace("\n", " ")
35
  keyphrases = extractor(input)
36
  out = "The Key Phrases in your text are:\n\n"
37
  for k in keyphrases:
38
  out += k + "\n"
39
- return out
 
 
 
 
 
 
 
 
 
 
 
40
 
41
- demo = gr.Interface(fn=keyphrases_out, inputs = "text", outputs = "text")
42
 
43
  demo.launch()
44
 
 
1
  import os
2
  import gradio as gr
3
+ import wikipediaapi as wk
4
+
5
 
6
  from transformers import (
7
  TokenClassificationPipeline,
 
31
  model_name = "ml6team/keyphrase-extraction-kbir-inspec"
32
  extractor = KeyphraseExtractionPipeline(model=model_name)
33
 
34
+
35
+ def keyphrases_out(input): #Not used but might be useful
36
  input = input.replace("\n", " ")
37
  keyphrases = extractor(input)
38
  out = "The Key Phrases in your text are:\n\n"
39
  for k in keyphrases:
40
  out += k + "\n"
41
+ return keyphrases
42
+
43
+ def wikipedia_search(input):
44
+ input = input.replace("\n", " ")
45
+ keyphrases = extractor(input)
46
+ wiki = wk.Wikipedia('en')
47
+ for k in keyphrases:
48
+ page = wiki.page(k)
49
+ if page.exists():
50
+ break
51
+ return page.summary
52
+
53
 
54
+ demo = gr.Interface(fn=wikipedia_search, inputs = "text", outputs = "text")
55
 
56
  demo.launch()
57