Created app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForTokenClassification
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
|
| 5 |
+
description = "Named Entity Recognition Using BERT"
|
| 6 |
+
title = "NERBERT"
|
| 7 |
+
examples = [["Hey, Alex here from London!"], ["My name is Wolfgang and I live in Berlin"]]
|
| 8 |
+
|
| 9 |
+
def findNER(example):
|
| 10 |
+
tokenizer = AutoTokenizer.from_pretrained("dslim/bert-base-NER")
|
| 11 |
+
model = AutoModelForTokenClassification.from_pretrained("dslim/bert-base-NER")
|
| 12 |
+
ner_pipeline = pipeline("ner", model=model, tokenizer=tokenizer)
|
| 13 |
+
return ner_pipeline(example)
|
| 14 |
+
|
| 15 |
+
interface = gr.Interface(fn=findNER, inputs='text', outputs='text', examples=examples, description=description, title=title)
|
| 16 |
+
interface.launch()
|