-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstreamlit_app.py
More file actions
66 lines (52 loc) · 2.66 KB
/
Copy pathstreamlit_app.py
File metadata and controls
66 lines (52 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import streamlit as st
from nlp import CustomerFeedbackAnalyzer
def main():
st.title("Echoes of Emotion - Sentiment Analysis")
st.write("Enter customer feedback below to analyze sentiment and generate a summary of likes and dislikes.")
analyzer = CustomerFeedbackAnalyzer()
feedback = st.text_area("Customer Feedback", height=200)
if st.button("Analyze"):
if not feedback.strip():
st.warning("Please enter some feedback text to analyze.")
else:
with st.spinner("Analyzing feedback..."):
result = analyzer.analyze_feedback(feedback)
sentiment = result['sentiment_analysis']['sentiment']
score = result['sentiment_analysis']['score']
details = result['sentiment_analysis']['details']
summary = result['summary']
st.subheader("Sentiment Analysis Result")
sentiment_emoji = {
'positive': '😊',
'negative': '😞',
'neutral': '😐'
}.get(sentiment.lower(), '')
sentiment_color = {
'positive': 'green',
'negative': 'red',
'neutral': 'gray'
}.get(sentiment.lower(), 'black')
st.markdown(f"Sentiment: <span style='color:{sentiment_color}; font-weight:bold; font-size:24px'>{sentiment.capitalize()} {sentiment_emoji}</span>", unsafe_allow_html=True)
st.markdown(f"**Score:** <span style='font-size:18px'>{score:.2f}</span>", unsafe_allow_html=True)
st.markdown("### Detailed Scores")
st.markdown(f"- Negative: {details.get('neg', 0):.3f}")
st.markdown(f"- Neutral: {details.get('neu', 0):.3f}")
st.markdown(f"- Positive: {details.get('pos', 0):.3f}")
st.markdown(f"- Compound: {details.get('compound', 0):.3f}")
st.markdown("### Summary of Customer Feedback")
liked = summary.get("liked", [])
disliked = summary.get("disliked", [])
if liked and liked != ['None']:
st.markdown("**👍 Liked:**")
for item in liked:
st.markdown(f"- {item}")
else:
st.markdown("**👍 Liked:** None")
if disliked and disliked != ['None']:
st.markdown("**👎 Disliked:**")
for item in disliked:
st.markdown(f"- {item}")
else:
st.markdown("**👎 Disliked:** None")
if __name__ == "__main__":
main()