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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -31
app.py CHANGED
@@ -74,21 +74,6 @@ def interact_with_together_api(messages, model_link):
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 = []
@@ -104,25 +89,33 @@ reset_button = st.sidebar.button('Reset Chat', on_click=reset_conversation)
104
 
105
  # Accept user input with input validation
106
  max_input_length = 100 # Maximum allowed character limit for user input
107
- if prompt := st.chat_input(f"Hi, I'm {selected_model}, let's chat (Max {max_input_length} characters)"):
108
  if len(prompt) > max_input_length:
109
  st.error(f"Maximum input length exceeded. Please limit your input to {max_input_length} characters.")
110
  else:
111
- with st.chat_message("user"):
112
- st.markdown(prompt)
113
- st.session_state.messages.append(("user", prompt))
114
-
115
- # Interact with the selected model
116
- assistant_response = interact_with_together_api(st.session_state.messages, model_links[selected_model])
117
-
118
- if assistant_response is not None:
119
- with st.empty():
120
- st.markdown("AI is typing...")
121
- st.empty()
122
- with st.chat_message("assistant"):
123
- st.markdown(assistant_response)
124
-
125
- st.session_state.messages.append(("assistant", assistant_response))
 
 
 
 
 
 
 
 
126
 
127
  # Display conversation insights
128
  st.sidebar.subheader("Conversation Insights")
 
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 = []
 
89
 
90
  # Accept user input with input validation
91
  max_input_length = 100 # Maximum allowed character limit for user input
92
+ if prompt := st.text_input(f"Hi, I'm {selected_model}, let's chat (Max {max_input_length} characters)"):
93
  if len(prompt) > max_input_length:
94
  st.error(f"Maximum input length exceeded. Please limit your input to {max_input_length} characters.")
95
  else:
96
+ with st.empty():
97
+ if st.button("Send"):
98
+ with st.spinner("Sending..."):
99
+ with st.chat_message("user"):
100
+ st.markdown(prompt)
101
+ st.session_state.messages.append(("user", prompt))
102
+
103
+ # Interact with the selected model
104
+ assistant_response = interact_with_together_api(st.session_state.messages, model_links[selected_model])
105
+
106
+ if assistant_response is not None:
107
+ with st.empty():
108
+ st.markdown("AI is typing...")
109
+ st.empty()
110
+ with st.chat_message("assistant"):
111
+ st.markdown(assistant_response)
112
+
113
+ if any(keyword in prompt.lower() for keyword in ["human", "therapist", "someone", "died", "death", "help", "suicide", "suffering", "crisis", "emergency", "support", "depressed", "anxiety", "lonely", "desperate", "struggling", "counseling", "distressed", "hurt", "pain", "grief", "trauma", "abuse", "danger", "risk", "urgent", "need assistance"]):
114
+ if not st.session_state.ask_intervention:
115
+ if st.button("After the analyzing our session you may need some extra help, so you can reach out to a certified therapist at +25493609747 Name: Ogega feel free to talk"):
116
+ st.write("You can reach out to a certified therapist at +25493609747.")
117
+
118
+ st.session_state.messages.append(("assistant", assistant_response))
119
 
120
  # Display conversation insights
121
  st.sidebar.subheader("Conversation Insights")