Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,12 +3,17 @@ from textblob import TextBlob
|
|
3 |
|
4 |
# Define the sentiment analysis function
|
5 |
def analyze_sentiment(text):
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
11 |
|
12 |
# Create a Gradio interface
|
13 |
iface = gr.Interface(fn=analyze_sentiment, inputs="text", outputs="text")
|
14 |
-
|
|
|
|
3 |
|
4 |
# Define the sentiment analysis function
|
5 |
def analyze_sentiment(text):
|
6 |
+
# Create a TextBlob object
|
7 |
+
blob = TextBlob(text)
|
8 |
+
# Extract sentiment
|
9 |
+
polarity = blob.sentiment.polarity
|
10 |
+
subjectivity = blob.sentiment.subjectivity
|
11 |
+
# Determine sentiment type
|
12 |
+
sentiment = "POSITIVE" if polarity >= 0 else "NEGATIVE"
|
13 |
+
# Return formatted string with results
|
14 |
+
return f"Sentiment: {sentiment}\nPolarity: {polarity:.2f}\nSubjectivity: {subjectivity:.2%}"
|
15 |
|
16 |
# Create a Gradio interface
|
17 |
iface = gr.Interface(fn=analyze_sentiment, inputs="text", outputs="text")
|
18 |
+
# Launch the interface
|
19 |
+
iface.launch()
|