Spaces:
Sleeping
Sleeping
File size: 1,208 Bytes
654b7ee |
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 38 |
import streamlit as st
import spacy
from spacy import displacy
from collections import Counter
# Load the English language model
nlp = spacy.load("en_core_web_sm")
def process_text(text):
# Process the text using the spaCy pipeline
doc = nlp(text)
# Extract the named entities
entities = [(ent.text, ent.label_) for ent in doc.ents]
# Count the occurrences of each entity type
entity_counts = Counter([ent[1] for ent in entities])
# Visualize the named entities using displacy
ent_html = displacy.render(doc, style="ent")
return ent_html, dict(entity_counts)
def main():
st.set_page_config(page_title="Named Entity Extraction")
st.title("Named Entity Extraction")
st.write("This app uses spaCy to extract named entities from the given text and visualize them.")
text = st.text_area("Text to Process", height=200, placeholder="Enter the text you want to analyze")
if st.button("Process Text"):
ent_html, entity_counts = process_text(text)
st.markdown(ent_html, unsafe_allow_html=True)
st.subheader("Entity Type Counts")
st.dataframe(entity_counts, use_container_width=True)
if __name__ == "__main__":
main() |