File size: 1,236 Bytes
c4ac47c 2f09011 cb77f6c 2f09011 cb77f6c 2f09011 7937069 cb77f6c 2f09011 b1a6713 2f09011 cb77f6c 2f09011 cb77f6c b1a6713 cb77f6c 2f09011 cb77f6c 2f09011 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
from transformers import pipeline
import gradio as gr
# Load the NER pipeline
ner = pipeline(
"ner",
model='kaiku03/bert-base-NER-finetuned_custom_complain_dataset_NER9',
aggregation_strategy="simple"
)
# Function for the Gradio app
def fn_ner(prompt):
entities = ner(prompt)
entity_info = "\n".join([f"{entity['entity_group']}: {entity['word']}" for entity in entities])
return entity_info
# Define example inputs and outputs
examples = [
"Subject: Defective Date: 08-13-2023 Product: XXX speaker Location: 456 Sound Avenue, Audiotown",
"Subject: Dirty Date: 08-10-2023 Product: UVW Television Location: 567 Willow Lane, Mediatown",
"Subject: Missing Parts Date: 08-10-2023 Product: XXX Furniture Set Location: Antipolo Rizal",
]
# Create Gradio interface
iface = gr.Interface(
fn=fn_ner,
inputs='text',
outputs='text',
examples=[[ex] for ex in examples],
title='Named Entity Recognition',
description='This demo performs named entity recognition (NER) on our custom made dataset. This dataset consist of very small training and testing samples resulting a very limited data our model to learn. ',
article='All done by Kaiku'
)
# Launch the interface
iface.launch()
|