File size: 816 Bytes
c33087b
 
 
44b923e
c33087b
 
 
 
 
 
 
 
 
44b923e
c33087b
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import gradio as gr
from transformers import pipeline

model_name = "dslim/bert-base-NER"

def ner_analysis(text):
    ner_pipeline = pipeline('ner', model=model_name, use_auth_token=None, aggregation_strategy="max")
    result = ner_pipeline(text)
    formatted = [f"{res['entity_group']}: {res['word']} ({res['score']:.2f})" for res in result]
    return "\n".join(formatted)

with gr.Blocks() as demo:
    gr.Markdown("# Named Entity Recognition")
    gr.Markdown("Powered by dslim/bert-base-NER")
    text_input = gr.Textbox(label="Text", placeholder="Enter text to analyze entities...", lines=3)
    output = gr.Textbox(label="Entities", lines=5)
    btn = gr.Button("Analyze")
    btn.click(fn=ner_analysis, inputs=text_input, outputs=output)

if __name__ == "__main__":
    demo.launch()