ogegadavis254 commited on
Commit
6fcf3cf
1 Parent(s): 425cbb0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -0
app.py CHANGED
@@ -74,6 +74,21 @@ def interact_with_together_api(messages, model_link):
74
  st.error(f"RequestException: {e}")
75
  return None
76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
  # Initialize chat history and session state attributes
78
  if "messages" not in st.session_state:
79
  st.session_state.messages = []
 
74
  st.error(f"RequestException: {e}")
75
  return None
76
 
77
+ # Function to perform sentiment analysis on the conversation
78
+ def analyze_sentiment(messages):
79
+ sentiments = []
80
+ for _, message in messages:
81
+ blob = TextBlob(message)
82
+ sentiment_score = blob.sentiment.polarity
83
+ sentiments.append(sentiment_score)
84
+
85
+ if sentiments: # Check if sentiments list is not empty
86
+ average_sentiment = sum(sentiments) / len(sentiments)
87
+ else:
88
+ average_sentiment = 0 # Set default sentiment to 0 if no messages are available
89
+
90
+ return average_sentiment
91
+
92
  # Initialize chat history and session state attributes
93
  if "messages" not in st.session_state:
94
  st.session_state.messages = []