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()