SarahMakk commited on
Commit
3409295
·
verified ·
1 Parent(s): bab9362

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -3
app.py CHANGED
@@ -59,15 +59,31 @@ if st.button("Classify Feedback"):
59
  if score >= CONFIDENCE_THRESHOLD:
60
  # Perform sentiment analysis on the sentence
61
  sentiment_result = sentiment_analyzer(sentence)
62
- sentiment_label = sentiment_result[0]["label"]
63
  sentiment_score = round(sentiment_result[0]["score"], 4)
64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  # Store the result for the category
66
  category_results[label].append({
67
  "sentence": sentence,
68
  "confidence": round(score, 4),
69
  "sentiment": sentiment_label,
70
- "sentiment_score": sentiment_score
 
 
71
  })
72
 
73
  # Check if there are any relevant categories
@@ -81,7 +97,13 @@ if st.button("Classify Feedback"):
81
  for result in results:
82
  st.write(f"- **Sentence**: {result['sentence']}")
83
  st.write(f" - Confidence: {result['confidence']}")
84
- st.write(f" - Sentiment: {result['sentiment']} (Score: {result['sentiment_score']})")
 
 
 
 
 
 
85
  st.write("") # Add a blank line for readability
86
 
87
  if not found_categories:
 
59
  if score >= CONFIDENCE_THRESHOLD:
60
  # Perform sentiment analysis on the sentence
61
  sentiment_result = sentiment_analyzer(sentence)
62
+ raw_label = sentiment_result[0]["label"]
63
  sentiment_score = round(sentiment_result[0]["score"], 4)
64
 
65
+ # Map the raw label to NEGATIVE or POSITIVE
66
+ if raw_label == "LABEL_0":
67
+ sentiment_label = "NEGATIVE"
68
+ sentiment_icon = "👎" # Thumbs-down icon for negative
69
+ sentiment_color = "red" # Red color for negative
70
+ elif raw_label == "LABEL_1":
71
+ sentiment_label = "POSITIVE"
72
+ sentiment_icon = "👍" # Thumbs-up icon for positive
73
+ sentiment_color = "green" # Green color for positive
74
+ else:
75
+ sentiment_label = raw_label # Fallback in case of unexpected label
76
+ sentiment_icon = "❓" # Question mark for unknown
77
+ sentiment_color = "gray" # Gray color for unknown
78
+
79
  # Store the result for the category
80
  category_results[label].append({
81
  "sentence": sentence,
82
  "confidence": round(score, 4),
83
  "sentiment": sentiment_label,
84
+ "sentiment_score": sentiment_score,
85
+ "sentiment_icon": sentiment_icon,
86
+ "sentiment_color": sentiment_color
87
  })
88
 
89
  # Check if there are any relevant categories
 
97
  for result in results:
98
  st.write(f"- **Sentence**: {result['sentence']}")
99
  st.write(f" - Confidence: {result['confidence']}")
100
+ # Use st.markdown with HTML to display the sentiment with icon and color
101
+ st.markdown(
102
+ f" - Sentiment: {result['sentiment_icon']} "
103
+ f"<span style='color:{result['sentiment_color']}'>{result['sentiment']}</span> "
104
+ f"(Score: {result['sentiment_score']})",
105
+ unsafe_allow_html=True
106
+ )
107
  st.write("") # Add a blank line for readability
108
 
109
  if not found_categories: