ogegadavis254 commited on
Commit
38c2b16
1 Parent(s): 668f790

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -7
app.py CHANGED
@@ -84,12 +84,18 @@ st.sidebar.write("A product proudly developed by Kisii University")
84
  if "messages" not in st.session_state:
85
  st.session_state.messages = []
86
  st.session_state.message_count = 0
 
 
 
 
 
 
87
 
88
  # Keywords for intervention
89
  intervention_keywords = [
90
  "human", "therapist", "someone", "died", "death", "help", "suicide", "suffering",
91
  "crisis", "emergency", "support", "depressed", "anxiety", "lonely", "desperate",
92
- "struggling", "counseling", "distressed", "hurt", "pain", "grief", "trauma", "die", "kill",
93
  "abuse", "danger", "risk", "urgent", "need assistance", "mental health", "talk to"
94
  ]
95
 
@@ -102,11 +108,12 @@ if prompt := st.chat_input(f"Hi, I'm {selected_model}, ask me a question"):
102
  st.session_state.messages.append(("user", prompt))
103
  st.session_state.message_count += 1
104
 
105
- # Check if intervention is needed based on bot response
106
- if any(keyword in prompt.lower() for keyword in intervention_keywords):
107
- # Intervention logic here
108
- with st.chat_message("assistant"):
109
  st.markdown("<span style='color:red;'>I have a feeling you may need to talk to a therapist. If you agree with me please contact +254793609747; Name: Davis. If you dont then keep talking to me as we figure this out.</span>", unsafe_allow_html=True)
 
110
 
111
  # Interact with the selected model
112
  assistant_response = interact_with_together_api(st.session_state.messages, model_links[selected_model])
@@ -115,8 +122,7 @@ if prompt := st.chat_input(f"Hi, I'm {selected_model}, ask me a question"):
115
  with st.empty():
116
  st.markdown("AI is typing...")
117
  st.empty()
118
- with st.chat_message("assistant"):
119
- st.markdown(assistant_response)
120
 
121
  # Add assistant response to chat history
122
  st.session_state.messages.append(("assistant", assistant_response))
 
84
  if "messages" not in st.session_state:
85
  st.session_state.messages = []
86
  st.session_state.message_count = 0
87
+ st.session_state.ask_intervention = False
88
+
89
+ # Display chat messages from history on app rerun
90
+ for message in st.session_state.messages:
91
+ with st.chat_message(message[0]):
92
+ st.markdown(message[1])
93
 
94
  # Keywords for intervention
95
  intervention_keywords = [
96
  "human", "therapist", "someone", "died", "death", "help", "suicide", "suffering",
97
  "crisis", "emergency", "support", "depressed", "anxiety", "lonely", "desperate",
98
+ "struggling", "counseling", "distressed", "hurt", "pain", "grief", "trauma", "die", "Kill",
99
  "abuse", "danger", "risk", "urgent", "need assistance", "mental health", "talk to"
100
  ]
101
 
 
108
  st.session_state.messages.append(("user", prompt))
109
  st.session_state.message_count += 1
110
 
111
+ # Check for intervention keywords in user input
112
+ for keyword in intervention_keywords:
113
+ if keyword in prompt.lower():
114
+ # Intervention logic here
115
  st.markdown("<span style='color:red;'>I have a feeling you may need to talk to a therapist. If you agree with me please contact +254793609747; Name: Davis. If you dont then keep talking to me as we figure this out.</span>", unsafe_allow_html=True)
116
+ break # Exit loop once intervention is triggered
117
 
118
  # Interact with the selected model
119
  assistant_response = interact_with_together_api(st.session_state.messages, model_links[selected_model])
 
122
  with st.empty():
123
  st.markdown("AI is typing...")
124
  st.empty()
125
+ st.markdown(assistant_response)
 
126
 
127
  # Add assistant response to chat history
128
  st.session_state.messages.append(("assistant", assistant_response))