Commit
·
3cf2fd4
1
Parent(s):
2ef326a
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,36 +2,28 @@ from transformers import pipeline
|
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
model_checkpoint = "MuntasirHossain/bert-finetuned-ner"
|
| 5 |
-
model = pipeline("ner", model=model_checkpoint, aggregation_strategy="simple")
|
| 6 |
|
|
|
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
|
| 12 |
def ner(text):
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
for result in results:
|
| 16 |
-
a += result['word'] + " : " + result['entity_group'] + ", "
|
| 17 |
-
a = a[0:len(a)-4] # removes the ', ' at the end of text
|
| 18 |
-
return a
|
| 19 |
-
|
| 20 |
|
| 21 |
description = "This AI model is trained to identify and classify named entities such as persons (PER), locations (LOC), organizations (ORG) and miscellaneous (MISC) \
|
| 22 |
in unstructured text."
|
| 23 |
title = "Named Entity Recognition"
|
| 24 |
theme = "grass"
|
| 25 |
examples=["Mount Everest is Earth's highest mountain, located in the Mahalangur Himal sub-range of the Himalayas. Edmund Hillary and Tenzing Norgay were the \
|
| 26 |
-
first climbers confirmed to have reached the summit of Mount Everest on May 29, 1953."]
|
| 27 |
|
| 28 |
-
gr.Interface(
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
description=description,
|
| 36 |
-
examples=examples,
|
| 37 |
-
).launch()
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
model_checkpoint = "MuntasirHossain/bert-finetuned-ner"
|
|
|
|
| 5 |
|
| 6 |
+
model = pipeline("ner", model=model_checkpoint, aggregation_strategy="simple")
|
| 7 |
|
| 8 |
+
examples = [
|
| 9 |
+
"Does Chicago have any stores and does Joe live here?",
|
| 10 |
+
]
|
| 11 |
|
| 12 |
def ner(text):
|
| 13 |
+
output = model(text)
|
| 14 |
+
return {"text": text, "entities": output}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
description = "This AI model is trained to identify and classify named entities such as persons (PER), locations (LOC), organizations (ORG) and miscellaneous (MISC) \
|
| 17 |
in unstructured text."
|
| 18 |
title = "Named Entity Recognition"
|
| 19 |
theme = "grass"
|
| 20 |
examples=["Mount Everest is Earth's highest mountain, located in the Mahalangur Himal sub-range of the Himalayas. Edmund Hillary and Tenzing Norgay were the \
|
| 21 |
+
first climbers confirmed to have reached the summit of Mount Everest on May 29, 1953."]
|
| 22 |
|
| 23 |
+
gr.Interface(ner,
|
| 24 |
+
gr.Textbox(placeholder="Enter sentence here..."),
|
| 25 |
+
gr.HighlightedText(),
|
| 26 |
+
title=title,
|
| 27 |
+
theme = theme,
|
| 28 |
+
description=description,
|
| 29 |
+
examples=examples).launch()
|
|
|
|
|
|
|
|
|