Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,23 +1,21 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
|
|
|
|
|
|
3 |
|
4 |
def analyze_sentiment(text):
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
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=
|
18 |
outputs="text",
|
19 |
title="Sentiment Analysis",
|
20 |
-
description="Enter text to analyze its sentiment (positive
|
21 |
)
|
22 |
|
23 |
if __name__ == "__main__":
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load sentiment analysis pipeline
|
5 |
+
sentiment_pipeline = pipeline("sentiment-analysis")
|
6 |
|
7 |
def analyze_sentiment(text):
|
8 |
+
result = sentiment_pipeline(text)[0]
|
9 |
+
label = result['label']
|
10 |
+
score = result['score']
|
11 |
+
return f"Sentiment: {label} (confidence: {score:.2f})"
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
iface = gr.Interface(
|
14 |
fn=analyze_sentiment,
|
15 |
+
inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
|
16 |
outputs="text",
|
17 |
title="Sentiment Analysis",
|
18 |
+
description="Enter text to analyze its sentiment (positive/negative)."
|
19 |
)
|
20 |
|
21 |
if __name__ == "__main__":
|