ogegadavis254 commited on
Commit
ae1aad0
1 Parent(s): a598f9f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -5
app.py CHANGED
@@ -128,16 +128,29 @@ st.sidebar.image("https://assets.isu.pub/document-structure/221118065013-a6029cf
128
  st.sidebar.write("A product proudly developed by Kisii University")
129
 
130
  # Accept user input
131
- if prompt := st.text_input(f"Hi, I'm {selected_model}, let's chat"):
132
  # Display user message in chat message container
 
 
 
133
  st.session_state.messages.append(("user", prompt))
 
134
  # Interact with the selected model
135
  assistant_response = interact_with_together_api(st.session_state.messages, model_links[selected_model])
136
 
137
  if assistant_response is not None:
138
  # Display assistant response in chat message container
 
 
 
 
 
 
 
 
 
 
 
 
 
139
  st.session_state.messages.append(("assistant", assistant_response))
140
-
141
- # Display chat messages from history
142
- # Add assistant response to chat history
143
- st.session_state.messages.append(("assistant", assistant_response))
 
128
  st.sidebar.write("A product proudly developed by Kisii University")
129
 
130
  # Accept user input
131
+ if prompt := st.chat_input(f"Hi, I'm {selected_model}, let's chat"):
132
  # Display user message in chat message container
133
+ with st.chat_message("user"):
134
+ st.markdown(prompt)
135
+ # Add user message to chat history
136
  st.session_state.messages.append(("user", prompt))
137
+
138
  # Interact with the selected model
139
  assistant_response = interact_with_together_api(st.session_state.messages, model_links[selected_model])
140
 
141
  if assistant_response is not None:
142
  # Display assistant response in chat message container
143
+ with st.empty():
144
+ st.markdown("AI is typing...")
145
+ st.empty()
146
+ st.markdown(assistant_response)
147
+
148
+ # Check if intervention is needed based on bot response
149
+ 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"]):
150
+ # Intervention logic here
151
+ if not st.session_state.ask_intervention:
152
+ if st.button("After the analysing 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"):
153
+ st.write("You can reach out to a certified therapist at +25493609747.")
154
+
155
+ # Add assistant response to chat history
156
  st.session_state.messages.append(("assistant", assistant_response))