Skip to content

Instantly share code, notes, and snippets.

@sharvaridhote
Last active February 2, 2021 14:37
Show Gist options
  • Save sharvaridhote/1e098474463cc24ffcec3439e237dd1f to your computer and use it in GitHub Desktop.
Save sharvaridhote/1e098474463cc24ffcec3439e237dd1f to your computer and use it in GitHub Desktop.
Spacy-Stremlit App
def load_model():
# declare global variables
global nlp
global textcat
nlp = spacy.load('C:/Project') ## will load the model from the model_path
textcat = nlp.get_pipe('textcat') ## will load the model file
def main():
"""Wikipedia Citation Needed NLP app with Spacy-Streamlit"""
st.title("Wikipedia Citation Needed Predictor")
our_image = Image.open(os.path.join('wiki_logo.png'))
st.image(our_image)
menu = ["Home", "NER", "Textcat","Explain Prediction"]
choice = st.sidebar.selectbox("Menu", menu)
if choice == "Home":
st.subheader("Tokenization")
raw_text = st.text_area("Your Text", "Enter 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("Named Entity Recognition")
raw_text = st.text_area("Your Text", "Enter Text Here")
docx = nlp(raw_text)
spacy_streamlit.visualize_ner(docx, labels=nlp.get_pipe('ner').labels)
elif choice == "Textcat":
st.subheader("Citation Needed ")
raw_text = st.text_area("Your Text", "Enter Text Here")
docx = nlp(raw_text)
spacy_streamlit.visualize_textcat(docx, title="Sentence Need Citation" )
elif choice == "Explain Prediction":
st.subheader("Why this predicted")
raw_text = st.text_area("Your Text", "Enter Text Here")
# get number of features input
num_features_input = st.number_input(label="Num of features to visualize",
min_value=1, max_value=7, step=1)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment