saritha5's picture
Update app.py
a6f9f12
raw
history blame
2.1 kB
#Core Packages
import streamlit as st
#nlp pkgs
import spacy
from spacy import displacy
import spacy_streamlit
from spacy_streamlit import visualize_ner
import en_core_web_sm
nlp = spacy.load("en_core_web_sm")
def main():
"""A simple NLP app with spacy-streamlit"""
spacy_model = "en_core_web_sm"
st.title('Entity Extraction')
menu = ["Home","NER"]
choice = st.sidebar.selectbox("Menu", menu)
if choice == "Home":
st.subheader("Tokenization")
raw_text = st.text_area("Your Text","Enter the Text Here")
docx = nlp(raw_text)
if st.button("Tokenize"):
spacy_streamlit.visualize_tokens(docx,attrs = ['text','pos_','dep_','ent_type_'])
elif choice == 'NER':
st.subheader("Name Entity Recognition")
raw_text = st.text_area("Your Text","Enter the Text Here")
docx = nlp(raw_text)
spacy_streamlit.visualize_ner(docx)
if __name__ == '__main__':
main()
#def prediction(raw_text):
#text1= NER(raw_text)
#st.write("List wise NERs:")
#st.write("------------------")
#st.write(f"{'Text' : <10}{'NER' : >10}")
#for word in text1.ents:
# st.write(word.text,"\t\t",word.label_)
#print()
#st.write("------------------")
#st.write("NERs in the sentence:")
#spacy_streamlit.visualize(displacy.render(text1,style="ent"))
#models = ["en_core_web_sm"]
#spacy_streamlit.visualize(text1,models = models)
#visualize_ner(text1, labels=nlp.get_pipe("ner").labels)
#raw_text = """Ai-Khanoum (/aɪ ˈhɑːnjuːm/, meaning Lady Moon; Uzbek: Oyxonim) is the archaeological site of a Hellenistic city in Takhar Province, Afghanistan.
#The city, whose original name is unknown,[a] was probably founded by an early ruler of the Seleucid Empire and served as a military and economic centre for the rulers of the Greco-Bactrian Kingdom until its destruction c. 145 BC.
#Rediscovered in 1961, the ruins of the city were excavated by a French team of archaeologists until the outbreak of conflict in Afghanistan in the late 1970s. """
#prediction(raw_text)