Spaces:
Runtime error
Runtime error
Walid Aissa
commited on
Commit
·
9831428
1
Parent(s):
c1811af
integration of the key-phrase extraction model with Gradio
Browse files- app.py +46 -1
- flagged/log.csv +32 -0
app.py
CHANGED
@@ -1,5 +1,50 @@
|
|
1 |
import os
|
2 |
-
import gradio as
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
|
5 |
|
|
|
1 |
import os
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
from transformers import (
|
5 |
+
TokenClassificationPipeline,
|
6 |
+
AutoModelForTokenClassification,
|
7 |
+
AutoTokenizer,
|
8 |
+
)
|
9 |
+
from transformers.pipelines import AggregationStrategy
|
10 |
+
import numpy as np
|
11 |
+
|
12 |
+
class KeyphraseExtractionPipeline(TokenClassificationPipeline):
|
13 |
+
def __init__(self, model, *args, **kwargs):
|
14 |
+
super().__init__(
|
15 |
+
model=AutoModelForTokenClassification.from_pretrained(model),
|
16 |
+
tokenizer=AutoTokenizer.from_pretrained(model),
|
17 |
+
*args,
|
18 |
+
**kwargs
|
19 |
+
)
|
20 |
+
|
21 |
+
def postprocess(self, model_outputs):
|
22 |
+
results = super().postprocess(
|
23 |
+
model_outputs=model_outputs,
|
24 |
+
aggregation_strategy=AggregationStrategy.SIMPLE,
|
25 |
+
)
|
26 |
+
return np.unique([result.get("word").strip() for result in results])
|
27 |
+
|
28 |
+
# Load pipeline
|
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 |
+
|
45 |
+
|
46 |
+
|
47 |
+
|
48 |
|
49 |
|
50 |
|
flagged/log.csv
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
text,output,flag,username,timestamp
|
2 |
+
"'Keyphrase extraction is a technique in text analysis where you extract the
|
3 |
+
important keyphrases from a document. Thanks to these keyphrases humans can
|
4 |
+
understand the content of a text very quickly and easily without reading it
|
5 |
+
completely. Keyphrase extraction was first done primarily by human annotators,
|
6 |
+
who read the text in detail and then wrote down the most important keyphrases.
|
7 |
+
The disadvantage is that if you work with a lot of documents, this process
|
8 |
+
can take a lot of time.
|
9 |
+
|
10 |
+
Here is where Artificial Intelligence comes in. Currently, classical machine
|
11 |
+
learning methods, that use statistical and linguistic features, are widely used
|
12 |
+
for the extraction process. Now with deep learning, it is possible to capture
|
13 |
+
the semantic meaning of a text even better than these classical methods.
|
14 |
+
Classical methods look at the frequency, occurrence and order of words
|
15 |
+
in the text, whereas these neural approaches can capture long-term
|
16 |
+
semantic dependencies and context of words in a text.",,,,2023-02-25 21:18:36.680367
|
17 |
+
"'Keyphrase extraction is a technique in text analysis where you extract the
|
18 |
+
important keyphrases from a document. Thanks to these keyphrases humans can
|
19 |
+
understand the content of a text very quickly and easily without reading it
|
20 |
+
completely. Keyphrase extraction was first done primarily by human annotators,
|
21 |
+
who read the text in detail and then wrote down the most important keyphrases.
|
22 |
+
The disadvantage is that if you work with a lot of documents, this process
|
23 |
+
can take a lot of time.
|
24 |
+
|
25 |
+
Here is where Artificial Intelligence comes in. Currently, classical machine
|
26 |
+
learning methods, that use statistical and linguistic features, are widely used
|
27 |
+
for the extraction process. Now with deep learning, it is possible to capture
|
28 |
+
the semantic meaning of a text even better than these classical methods.
|
29 |
+
Classical methods look at the frequency, occurrence and order of words
|
30 |
+
in the text, whereas these neural approaches can capture long-term
|
31 |
+
semantic dependencies and context of words in a text.",,,,2023-02-25 21:18:38.087039
|
32 |
+
,,,,2023-02-25 21:18:40.419138
|