Shantala's picture
Update app.py with the code for the Panel app
a4d0792
import panel as pn
import textblob
import pandas as pd
def sentiment_analysis(text):
"""
Performs sentiment analysis on the given text and returns a dataframe with the polarity score and subjectivity score.
Args:
text: The text to be analyzed.
Returns:
A dataframe with the polarity score and subjectivity score.
"""
blob = textblob.TextBlob(text)
polarity = blob.sentiment.polarity
subjectivity = blob.sentiment.subjectivity
df = pd.DataFrame([
["Polarity", polarity],
["Subjectivity", subjectivity]],
columns=['Measure', 'Score'])
return df
# Create the title and description for the app
title = "# TextBlob Polarity and Subjectivity Scores"
description = """
### 'Polarity' and 'Subjectivity' pertain to sentiment analysis of a text. The polarity score is a float within the range [-1.0, 1.0], where -1.0 indicates wholly negative sentiment and 1.0 indicates wholly positive sentiment. The subjectivity is a float within the range [0.0, 1.0], where 0.0 is very objective and 1.0 is very subjective.
"""
# Create the Panel input component
text_input = pn.widgets.TextInput(placeholder="Enter some text and press Enter...")
# Bind the function to the text_input widget
sentiment_df = pn.bind(sentiment_analysis, text_input)
# Define the app layout
app = pn.Column(
title,
description,
pn.Row(text_input, sentiment_df)
)
# Display the app
app.servable()