File size: 1,414 Bytes
7ae8600
a4d0792
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7ae8600
 
a4d0792
 
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
39
40
41
42
43
44
45
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()