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