Spaces:
Runtime error
Runtime error
Create app.py
Browse filesPython script added
app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from textblob import TextBlob
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
# define a function that accepts a text input and returns a dataframe of the polarity and subjectivity scores from TextBlob
|
| 7 |
+
def sentiment_analysis(text):
|
| 8 |
+
tb = TextBlob(text)
|
| 9 |
+
df = pd.DataFrame([['Polarity', tb.sentiment.polarity],
|
| 10 |
+
['Subjectivity', tb.sentiment.subjectivity]],
|
| 11 |
+
columns=['Measure', 'Score'])
|
| 12 |
+
df.Score.round(decimals=2)
|
| 13 |
+
return df
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
# create the title and description for the app
|
| 17 |
+
|
| 18 |
+
title = "TextBlob Polarity and Subjectivity Scores"
|
| 19 |
+
description = """
|
| 20 |
+
'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.
|
| 21 |
+
"""
|
| 22 |
+
# design the Gradio app
|
| 23 |
+
app = gr.Interface(
|
| 24 |
+
title=title,
|
| 25 |
+
description=description,
|
| 26 |
+
fn=sentiment_analysis,
|
| 27 |
+
inputs=gr.Textbox(placeholder="Enter your text here..."),
|
| 28 |
+
outputs=gr.Dataframe(),
|
| 29 |
+
examples=[["Happy days are here again!"]])
|
| 30 |
+
|
| 31 |
+
# launch the app
|
| 32 |
+
app.launch(share=True) #generates a shareable public URL
|