ogegadavis254 commited on
Commit
b09bd8c
1 Parent(s): d362116

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -21
app.py CHANGED
@@ -1,4 +1,3 @@
1
-
2
  import streamlit as st
3
  import requests
4
  import os
@@ -12,6 +11,7 @@ def reset_conversation():
12
  Resets Conversation
13
  '''
14
  st.session_state.messages = []
 
15
  return None
16
 
17
  # Define model links for the Addiction Recovery and Mental Health models
@@ -76,27 +76,14 @@ def interact_with_together_api(messages, model_link):
76
  st.error(f"Error communicating with the API: {e}")
77
  return None
78
 
79
- # Create sidebar with model selection dropdown and reset button
80
- selected_model = st.sidebar.selectbox("Select Model", list(model_links.keys()))
81
- st.sidebar.button('Reset Chat', on_click=reset_conversation)
82
-
83
- # Add cautionary message about testing phase at the bottom of the sidebar
84
- st.sidebar.markdown("**Note**: This model is still in the beta phase. Responses may be inaccurate or undesired. Use it cautiously, especially for critical issues.")
85
-
86
- # Add logo and text to the sidebar
87
- st.sidebar.image("https://assets.isu.pub/document-structure/221118065013-a6029cf3d563afaf9b946bb9497d45d4/v1/2841525b232adaef7bd0efe1da81a4c5.jpeg", width=200)
88
- st.sidebar.write("A product proudly developed by Kisii University")
89
-
90
- # Initialize chat history
91
  if "messages" not in st.session_state:
92
  st.session_state.messages = []
93
- st.session_state.message_count = 0
94
  st.session_state.ask_intervention = False
95
 
96
- # Display chat messages from history on app rerun
97
- for message in st.session_state.messages:
98
- with st.chat_message(message[0]):
99
- st.markdown(message[1])
100
 
101
  # Accept user input
102
  if prompt := st.chat_input(f"Hi, I'm {selected_model}, let's chat"):
@@ -105,7 +92,6 @@ if prompt := st.chat_input(f"Hi, I'm {selected_model}, let's chat"):
105
  st.markdown(prompt)
106
  # Add user message to chat history
107
  st.session_state.messages.append(("user", prompt))
108
- st.session_state.message_count += 1
109
 
110
  # Interact with the selected model
111
  assistant_response = interact_with_together_api(st.session_state.messages, model_links[selected_model])
@@ -116,12 +102,13 @@ if prompt := st.chat_input(f"Hi, I'm {selected_model}, let's chat"):
116
  st.markdown("AI is typing...")
117
  st.empty()
118
  st.markdown(assistant_response)
 
119
  # Check if intervention is needed based on bot response
120
  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"]):
121
  # Intervention logic here
122
  if not st.session_state.ask_intervention:
123
  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"):
124
  st.write("You can reach out to a certified therapist at +25493609747.")
125
-
126
  # Add assistant response to chat history
127
- st.session_state.messages.append(("assistant", assistant_response))
 
 
1
  import streamlit as st
2
  import requests
3
  import os
 
11
  Resets Conversation
12
  '''
13
  st.session_state.messages = []
14
+ st.session_state.ask_intervention = False
15
  return None
16
 
17
  # Define model links for the Addiction Recovery and Mental Health models
 
76
  st.error(f"Error communicating with the API: {e}")
77
  return None
78
 
79
+ # Initialize chat history and session state attributes
 
 
 
 
 
 
 
 
 
 
 
80
  if "messages" not in st.session_state:
81
  st.session_state.messages = []
 
82
  st.session_state.ask_intervention = False
83
 
84
+ # Create sidebar with model selection dropdown and reset button
85
+ selected_model = st.sidebar.selectbox("Select Model", list(model_links.keys()))
86
+ reset_button = st.sidebar.button('Reset Chat', on_click=reset_conversation)
 
87
 
88
  # Accept user input
89
  if prompt := st.chat_input(f"Hi, I'm {selected_model}, let's chat"):
 
92
  st.markdown(prompt)
93
  # Add user message to chat history
94
  st.session_state.messages.append(("user", prompt))
 
95
 
96
  # Interact with the selected model
97
  assistant_response = interact_with_together_api(st.session_state.messages, model_links[selected_model])
 
102
  st.markdown("AI is typing...")
103
  st.empty()
104
  st.markdown(assistant_response)
105
+
106
  # Check if intervention is needed based on bot response
107
  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"]):
108
  # Intervention logic here
109
  if not st.session_state.ask_intervention:
110
  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"):
111
  st.write("You can reach out to a certified therapist at +25493609747.")
112
+
113
  # Add assistant response to chat history
114
+ st.session_state.messages.append(("assistant", assistant_response))