Spaces:
Runtime error
Runtime error
Create syntiment_analysis.py
Browse files
components/syntiment_analysis.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
|
3 |
+
class EnhancedSentimentAnalyzer:
|
4 |
+
"""Advanced sentiment analysis with additional techniques"""
|
5 |
+
def __init__(self):
|
6 |
+
self.sentiment_pipeline = pipeline('sentiment-analysis')
|
7 |
+
|
8 |
+
def analyze(self, text: str) -> Dict[str, Any]:
|
9 |
+
"""Analyze sentiment with advanced techniques"""
|
10 |
+
analysis = self.sentiment_pipeline(text)
|
11 |
+
return analysis[0]
|
12 |
+
|
13 |
+
def detailed_analysis(self, text: str) -> Dict[str, Any]:
|
14 |
+
"""Provide a more detailed sentiment analysis"""
|
15 |
+
scores = self.sentiment_pipeline(text)[0]
|
16 |
+
if scores['label'] == 'POSITIVE':
|
17 |
+
sentiment = "Positive"
|
18 |
+
elif scores['label'] == 'NEGATIVE':
|
19 |
+
sentiment = "Negative"
|
20 |
+
else:
|
21 |
+
sentiment = "Neutral"
|
22 |
+
return {
|
23 |
+
"scores": scores,
|
24 |
+
"sentiment": sentiment
|
25 |
+
}
|