Spaces:
Runtime error
Runtime error
Jingxiang Mo
commited on
Commit
•
4970856
1
Parent(s):
9522bb7
Interface improvements
Browse files- app.py +26 -48
- requirements.txt +5 -0
app.py
CHANGED
@@ -30,62 +30,40 @@ class KeyphraseExtractionPipeline(TokenClassificationPipeline):
|
|
30 |
model_name = "ml6team/keyphrase-extraction-kbir-inspec"
|
31 |
extractor = KeyphraseExtractionPipeline(model=model_name)
|
32 |
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
understand the content of a text very quickly and easily without reading it
|
37 |
-
completely. Keyphrase extraction was first done primarily by human annotators,
|
38 |
-
who read the text in detail and then wrote down the most important keyphrases.
|
39 |
-
The disadvantage is that if you work with a lot of documents, this process
|
40 |
-
can take a lot of time.
|
41 |
-
|
42 |
-
Here is where Artificial Intelligence comes in. Currently, classical machine
|
43 |
-
learning methods, that use statistical and linguistic features, are widely used
|
44 |
-
for the extraction process. Now with deep learning, it is possible to capture
|
45 |
-
the semantic meaning of a text even better than these classical methods.
|
46 |
-
Classical methods look at the frequency, occurrence and order of words
|
47 |
-
in the text, whereas these neural approaches can capture long-term
|
48 |
-
semantic dependencies and context of words in a text.
|
49 |
-
""".replace("\n", " ")
|
50 |
-
|
51 |
-
keyphrases = extractor(text)
|
52 |
-
|
53 |
-
print(keyphrases)
|
54 |
-
|
55 |
-
|
56 |
-
def keyphrases_out(input):
|
57 |
-
input = input.replace("\n", " ")
|
58 |
-
keyphrases = extractor(input)
|
59 |
-
out = "The Key Phrases in your text are:\n\n"
|
60 |
-
for k in keyphrases:
|
61 |
-
out += k + "\n"
|
62 |
return keyphrases
|
63 |
|
64 |
-
def wikipedia_search(input):
|
65 |
input = input.replace("\n", " ")
|
66 |
-
keyphrases =
|
67 |
wiki = wk.Wikipedia('en')
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
# for k in keyphrases:
|
76 |
-
# page = wiki.page(k)
|
77 |
-
# if page.exists():
|
78 |
-
# break
|
79 |
-
# return page.summary
|
80 |
|
81 |
# =====[ DEFINE INTERFACE ]===== #'
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
|
88 |
|
|
|
|
|
89 |
|
|
|
|
|
|
|
90 |
|
|
|
|
|
91 |
|
|
|
|
|
|
30 |
model_name = "ml6team/keyphrase-extraction-kbir-inspec"
|
31 |
extractor = KeyphraseExtractionPipeline(model=model_name)
|
32 |
|
33 |
+
#TODO: add further preprocessing
|
34 |
+
def keyphrases_extraction(text: str) -> str:
|
35 |
+
keyphrases = extractor(text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
return keyphrases
|
37 |
|
38 |
+
def wikipedia_search(input: str) -> str:
|
39 |
input = input.replace("\n", " ")
|
40 |
+
keyphrases = keyphrases_extraction(input)
|
41 |
wiki = wk.Wikipedia('en')
|
42 |
+
|
43 |
+
try :
|
44 |
+
#TODO: add better extraction and search
|
45 |
+
page = wiki.page(keyphrases[0])
|
46 |
+
return page.summary
|
47 |
+
except:
|
48 |
+
return "I cannot answer this question"
|
|
|
|
|
|
|
|
|
|
|
49 |
|
50 |
# =====[ DEFINE INTERFACE ]===== #'
|
51 |
+
title = "Azza Chatbot"
|
52 |
+
examples = [
|
53 |
+
["Where is the Eiffel Tower?"],
|
54 |
+
["What is the population of France?"]
|
55 |
+
]
|
56 |
|
57 |
|
58 |
+
demo = gr.Interface(
|
59 |
+
title = title,
|
60 |
|
61 |
+
fn=wikipedia_search,
|
62 |
+
inputs = "text",
|
63 |
+
outputs = "text",
|
64 |
|
65 |
+
examples=examples
|
66 |
+
)
|
67 |
|
68 |
+
if __name__ == "__main__":
|
69 |
+
demo.launch(share=True)
|
requirements.txt
CHANGED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
os
|
2 |
+
gradio
|
3 |
+
wikipedia-api
|
4 |
+
transformers
|
5 |
+
transformers.pipelines
|