Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from textblob import TextBlob
|
3 |
+
|
4 |
+
def analyze_sentiment(text):
|
5 |
+
blob = TextBlob(text)
|
6 |
+
polarity = blob.sentiment.polarity
|
7 |
+
if polarity > 0:
|
8 |
+
sentiment = "Positive π"
|
9 |
+
elif polarity < 0:
|
10 |
+
sentiment = "Negative π"
|
11 |
+
else:
|
12 |
+
sentiment = "Neutral π"
|
13 |
+
return f"Sentiment: {sentiment}\nPolarity Score: {polarity:.2f}"
|
14 |
+
|
15 |
+
iface = gr.Interface(
|
16 |
+
fn=analyze_sentiment,
|
17 |
+
inputs=gr.Textbox(lines=3, placeholder="Enter text here..."),
|
18 |
+
outputs="text",
|
19 |
+
title="Sentiment Analysis",
|
20 |
+
description="Enter text to analyze its sentiment (positive, negative, or neutral)."
|
21 |
+
)
|
22 |
+
|
23 |
+
if __name__ == "__main__":
|
24 |
+
iface.launch()
|