Spaces:
Runtime error
Runtime error
README
Browse files- README.md +5 -5
- app.py +55 -0
- requirements.txt +3 -0
README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 3.4
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
|
|
1 |
---
|
2 |
+
title: NER
|
3 |
+
emoji: 🦀
|
4 |
+
colorFrom: green
|
5 |
+
colorTo: purple
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 3.1.4
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
app.py
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from tner import TransformersNER
|
3 |
+
from spacy import displacy
|
4 |
+
|
5 |
+
# model = TransformersNER("tner/roberta-large-ontonotes5")
|
6 |
+
model = TransformersNER("tner/bertweet-large-tweetner7-all")
|
7 |
+
|
8 |
+
examples = [
|
9 |
+
"Jacob Collier is a Grammy awarded artist from England.",
|
10 |
+
'Get the all-analog Classic Vinyl Edition of "Takin\' Off" Album from {@herbiehancock@} via {@bluenoterecords@} link below: {{URL}}',
|
11 |
+
"I’m so happy that the {@The New York Times@} sees in {@Mondaire Jones@} and {@Jamaal Bowman@} what the progressive grassroots in Westchester, Rockland and the Bronx sees ! They will both be extraordinary Congresspersons ! #cvhpower #nycd17 # nycd16",
|
12 |
+
"When Sebastian Thrun started working on self-driving cars at Google in 2007 , few people outside of the company took him seriously.",
|
13 |
+
"But Google is starting from behind. The company made a late push into hardware, and Apple’s Siri, available on iPhones, and Amazon’s Alexa software, which runs on its Echo and Dot devices, have clear leads in consumer adoption."
|
14 |
+
]
|
15 |
+
|
16 |
+
|
17 |
+
def predict(text):
|
18 |
+
output = model.predict([text])
|
19 |
+
tokens = output['input'][0]
|
20 |
+
|
21 |
+
def retain_char_position(p):
|
22 |
+
if p == 0:
|
23 |
+
return 0
|
24 |
+
return len(' '.join(tokens[:p])) + 1
|
25 |
+
|
26 |
+
doc = {
|
27 |
+
"text": text,
|
28 |
+
"ents": [{
|
29 |
+
"start": retain_char_position(entity['position'][0]),
|
30 |
+
"end": retain_char_position(entity['position'][-1]) + len(entity['entity'][-1]),
|
31 |
+
"label": entity['type']
|
32 |
+
} for entity in output['entity_prediction'][0]],
|
33 |
+
"title": None
|
34 |
+
}
|
35 |
+
|
36 |
+
html = displacy.render(doc, style="ent", page=True, manual=True, minify=True)
|
37 |
+
html = (
|
38 |
+
"<div style='max-width:100%; max-height:360px; overflow:auto'>"
|
39 |
+
+ html
|
40 |
+
+ "</div>"
|
41 |
+
)
|
42 |
+
|
43 |
+
return html
|
44 |
+
|
45 |
+
|
46 |
+
demo = gr.Interface(
|
47 |
+
fn=predict,
|
48 |
+
inputs=gr.inputs.Textbox(
|
49 |
+
lines=5,
|
50 |
+
placeholder="Input sentence...",
|
51 |
+
),
|
52 |
+
outputs="html",
|
53 |
+
examples=examples
|
54 |
+
)
|
55 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
spacy
|
2 |
+
tner
|
3 |
+
allennlp==2.10.0
|