Artificial Intelligence 13 min read

Building a Streamlit Web Application for NLP Tasks: Sentiment Analysis, Entity Extraction, and Text Summarization

This tutorial demonstrates how to create a lightweight Streamlit web app in Python that lets users select and run common NLP services—sentiment analysis, named‑entity recognition, and text summarization—by integrating libraries such as TextBlob, spaCy, and Gensim, with clear code examples and visual output.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
Building a Streamlit Web Application for NLP Tasks: Sentiment Analysis, Entity Extraction, and Text Summarization

The article introduces the broad field of web/app development for machine‑learning models and explains why Streamlit, a simple Python API, is ideal for quickly building front‑end interfaces that showcase NLP services without requiring extensive full‑stack expertise.

First, install Streamlit (e.g., pip3 install streamlit ) and import it in your script.

Use Streamlit’s title, header, and subheader functions to create a clear UI:

st.title("Natural Language Processing Web Application Example")
st.subheader("What type of NLP service would you like to use?")

Add a dropdown menu for task selection with st.selectbox :

option = st.selectbox('NLP Service', ('Sentiment Analysis', 'Entity Extraction', 'Text Summarization'))

Provide a text input area for the user’s document:

st.subheader("Enter the text you'd like to analyze.")
text = st.text_input('Enter text')

Sentiment Analysis : Tokenize the input into sentences, compute polarity with TextBlob, and plot the scores using st.line_chart . Also display overall polarity and subjectivity.

from textblob import TextBlob
sents = sent_tokenize(text)
entireText = TextBlob(text)
sentScores = []
for sent in sents:
    sentScores.append(TextBlob(sent).sentiment[0])
st.line_chart(sentScores)
sentimentTotal = entireText.sentiment
st.write("The sentiment of the overall text below.")
st.write(sentimentTotal)

Named Entity Recognition (NER) : Load spaCy’s English model, extract entities and their labels, then organize them by type using a helper function.

import spacy
from spacy import displacy
nlp = spacy.load('en_core_web_sm')
entities = []
entityLabels = []
doc = nlp(text)
for ent in doc.ents:
    entities.append(ent.text)
    entityLabels.append(ent.label_)
entDict = dict(zip(entities, entityLabels))

def entRecognizer(entDict, typeEnt):
    return [ent for ent in entDict if entDict[ent] == typeEnt]

entOrg = entRecognizer(entDict, "ORG")
entPerson = entRecognizer(entDict, "PERSON")
# ... other types
st.write("Organization Entities: " + str(entOrg))
st.write("Personal Entities: " + str(entPerson))

Text Summarization : Use Gensim’s summarize function to generate a concise summary of the input text, displaying it with st.subheader and st.write .

from gensim.summarization.summarizer import summarize
summWords = summarize(text)
st.subheader("Summary")
st.write(summWords)

The full script combines all imports, UI elements, and conditional logic for the three NLP services, providing a compact yet functional example that can be run with a single streamlit run command.

# Complete example
import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt
from textblob import TextBlob
from nltk.tokenize import sent_tokenize
from gensim.summarization.summarizer import summarize
import spacy
nlp = spacy.load('en_core_web_sm')

st.title("Natural Language Processing Web Application Example")
option = st.selectbox('NLP Service', ('Sentiment Analysis', 'Entity Extraction', 'Text Summarization'))
st.subheader("Enter the text you'd like to analyze.")
text = st.text_input('Enter text')

if option == 'Sentiment Analysis':
    # sentiment analysis code (as above)
    pass
elif option == 'Entity Extraction':
    # NER code (as above)
    pass
else:
    # summarization code (as above)
    pass
sentiment analysisNLPEntity RecognitionText SummarizationStreamlit
Python Programming Learning Circle
Written by

Python Programming Learning Circle

A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.