yashaswini278 commited on
Commit
48ae580
1 Parent(s): 22d6db5

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +14 -0
  2. engine.py +20 -0
  3. requirements.txt +0 -0
app.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from engine import SentimentAnalyzer
2
+ import streamlit as st
3
+
4
+ setiment_analysis = SentimentAnalyzer()
5
+
6
+ st.title("User Sentiment Analysis")
7
+
8
+ sentence = st.text_input("Enter a sentence:")
9
+
10
+ if sentence:
11
+ label = setiment_analysis.get_sentiment(sentence)
12
+
13
+ st.write(f"Sentiment analysis result: {label}")
14
+
engine.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+
3
+ class SentimentAnalyzer:
4
+ def __init__(self) -> None:
5
+ self.analyzer = pipeline("sentiment-analysis", model = "distilbert-base-uncased-finetuned-sst-2-english")
6
+
7
+ def score_sentiment(self, sentence: str) -> float:
8
+ return self.analyzer(sentence)[0]
9
+
10
+ def get_sentiment(self, sentence: str) -> str:
11
+ sentiment_score = self.score_sentiment(sentence)
12
+ return sentiment_score['label']
13
+
14
+ if __name__ == "__main__":
15
+ sentence = "This place is good"
16
+ sentiment_analyzer = SentimentAnalyzer()
17
+ print(sentiment_analyzer.get_sentiment(sentence))
18
+
19
+
20
+
requirements.txt ADDED
Binary file (72 Bytes). View file