File size: 1,230 Bytes
5cb152c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25732ab
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
from textblob import TextBlob
import pandas as pd
import gradio as gr


# define a function that accepts a text input and returns a dataframe of the polarity and subjectivity scores from TextBlob
def sentiment_analysis(text):
  tb = TextBlob(text)
  df = pd.DataFrame([['Polarity', tb.sentiment.polarity],
                     ['Subjectivity', tb.sentiment.subjectivity]],
                    columns=['Measure', 'Score'])
  df.Score.round(decimals=2)
  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.
"""
# design the Gradio app
app = gr.Interface(
  title=title,
  description=description,
  fn=sentiment_analysis,
  inputs=gr.Textbox(placeholder="Enter your text here..."),
  outputs=gr.Dataframe(),
  examples=[["Happy days are here again!"]])

# launch the app
app.launch() #generates a shareable public URL