import streamlit as st from transformers import pipeline # Load NER model @st.cache_resource def load_ner_model(): return pipeline("ner", grouped_entities=True) ner_model = load_ner_model() # Set the title with custom style st.markdown( "

Named Entity Recognition

", unsafe_allow_html=True ) # Set up text input with a description st.write( "

Enter your text below for entity recognition.

", unsafe_allow_html=True ) # Center the input text area text_input = st.text_area( "Text Input", placeholder="Type your text here...", height=200 ) # Customize the button and center it button_style = """ """ st.markdown(button_style, unsafe_allow_html=True) # Button to trigger NER model if st.button("Recognize Entities"): if text_input: with st.spinner("Processing..."): entities = ner_model(text_input) if entities: st.subheader("Named Entities") # Loop through entities and display with improved visibility for entity in entities: entity_html = f"""
Entity: {entity['word']}
Type: {entity['entity_group']}
Confidence: {entity['score']:.2f}
""" st.markdown(entity_html, unsafe_allow_html=True) else: st.write("No named entities found in the text.") else: st.error("Please enter some text for entity recognition.")