Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from textblob import TextBlob
|
3 |
+
|
4 |
+
# Define the sentiment analysis function
|
5 |
+
def analyze_sentiment(text):
|
6 |
+
blob = TextBlob(text)
|
7 |
+
polarity = blob.sentiment.polarity
|
8 |
+
subjectivity = blob.sentiment.subjectivity
|
9 |
+
sentiment = "POSITIVE" if polarity >= 0 else "NEGATIVE"
|
10 |
+
return f"Sentiment: {sentiment}\nPolarity: {polarity:.2f}\nSubjectivity: {subjectivity:.2%}"
|
11 |
+
|
12 |
+
# Create a Gradio interface
|
13 |
+
iface = gr.Interface(fn=analyze_sentiment, inputs="text", outputs="text")
|
14 |
+
iface.launch()
|