Spaces:
Build error
Build error
Commit
·
04ae9ec
1
Parent(s):
6d21fc4
Highlighting Component Addition
Browse files
app.py
CHANGED
|
@@ -49,8 +49,16 @@ def ner_tagging(text_1):
|
|
| 49 |
prediction = np.argmax(output, axis=-1)[0]
|
| 50 |
|
| 51 |
prediction = [mapping[str(i)] for i in prediction]
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
text_1 = gr.inputs.Textbox(lines=5)
|
| 56 |
ner_tag = gr.outputs.Textbox()
|
|
@@ -61,7 +69,7 @@ with open("vocab.json",'r') as f:
|
|
| 61 |
lookup_layer = keras.layers.StringLookup(vocabulary=vocab['tokens'])
|
| 62 |
|
| 63 |
iface = gr.Interface(ner_tagging,
|
| 64 |
-
inputs=text_1,outputs=
|
| 65 |
["He said further scientific study was required and if it was found that action was needed it should be taken by the European Union ."]], title="Named Entity Recognition with Transformers",
|
| 66 |
description = "Named Entity Recognition with Transformers on CoNLL2003 Dataset",
|
| 67 |
article = "Author: <a href=\"https://huggingface.co/reichenbach\">Rishav Chandra Varma</a>")
|
|
|
|
| 49 |
prediction = np.argmax(output, axis=-1)[0]
|
| 50 |
|
| 51 |
prediction = [mapping[str(i)] for i in prediction]
|
| 52 |
+
|
| 53 |
+
text_2 = text_1.split(" ")
|
| 54 |
+
output = []
|
| 55 |
+
for w in range(len(text_2)):
|
| 56 |
+
if prediction[w] != "O":
|
| 57 |
+
output.extend([(text_2[w], prediction[w]), (" ", None)])
|
| 58 |
+
else:
|
| 59 |
+
output.extend([(text_2[w], None), (" ", None)])
|
| 60 |
+
|
| 61 |
+
return output
|
| 62 |
|
| 63 |
text_1 = gr.inputs.Textbox(lines=5)
|
| 64 |
ner_tag = gr.outputs.Textbox()
|
|
|
|
| 69 |
lookup_layer = keras.layers.StringLookup(vocabulary=vocab['tokens'])
|
| 70 |
|
| 71 |
iface = gr.Interface(ner_tagging,
|
| 72 |
+
inputs=text_1,outputs=['highlight'], examples=[['EU rejects German call to boycott British lamb .'],
|
| 73 |
["He said further scientific study was required and if it was found that action was needed it should be taken by the European Union ."]], title="Named Entity Recognition with Transformers",
|
| 74 |
description = "Named Entity Recognition with Transformers on CoNLL2003 Dataset",
|
| 75 |
article = "Author: <a href=\"https://huggingface.co/reichenbach\">Rishav Chandra Varma</a>")
|