Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -11,7 +11,6 @@ def reset_conversation():
|
|
11 |
Resets Conversation
|
12 |
'''
|
13 |
st.session_state.messages = []
|
14 |
-
st.session_state.ask_intervention = False
|
15 |
return None
|
16 |
|
17 |
def analyze_diagnosis(messages, model_link):
|
@@ -106,46 +105,35 @@ def interact_with_together_api(messages, model_link):
|
|
106 |
st.error(f"Error communicating with the API: {e}")
|
107 |
return None
|
108 |
|
109 |
-
# Initialize chat history
|
110 |
if "messages" not in st.session_state:
|
111 |
st.session_state.messages = []
|
112 |
-
st.session_state.ask_intervention = False
|
113 |
|
114 |
# Create sidebar with model selection dropdown and reset button
|
115 |
selected_model = st.sidebar.selectbox("Select Model", list(model_links.keys()))
|
116 |
reset_button = st.sidebar.button('Reset Chat', on_click=reset_conversation)
|
117 |
|
118 |
# Add diagnostic feature to the sidebar
|
119 |
-
if st.session_state.messages:
|
120 |
-
with st.sidebar:
|
121 |
st.subheader("Diagnosis")
|
122 |
-
st.markdown("<div style='color: #1E90FF; font-size: 16px; font-weight: bold;'>Analyzing...</div>", unsafe_allow_html=True)
|
123 |
|
124 |
diagnosis = analyze_diagnosis(st.session_state.messages, model_links[selected_model])
|
125 |
if diagnosis:
|
126 |
-
st.
|
127 |
-
|
128 |
-
# Add additional features on the sidebar
|
129 |
-
st.sidebar.markdown("---")
|
130 |
-
st.sidebar.subheader("Self-care and Support")
|
131 |
-
st.sidebar.markdown("📝 Journaling")
|
132 |
-
st.sidebar.markdown("🎯 Goal Setting")
|
133 |
-
st.sidebar.markdown("😊 Mood Tracking")
|
134 |
-
st.sidebar.markdown("🛀 Self-care Tips")
|
135 |
|
136 |
# Add cautionary message about testing phase at the bottom of the sidebar
|
137 |
-
st.sidebar.markdown("---")
|
138 |
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.")
|
139 |
|
140 |
# Add logo and text to the sidebar
|
141 |
-
st.sidebar.markdown("---")
|
142 |
st.sidebar.image("https://assets.isu.pub/document-structure/221118065013-a6029cf3d563afaf9b946bb9497d45d4/v1/2841525b232adaef7bd0efe1da81a4c5.jpeg", width=200)
|
143 |
st.sidebar.write("A product proudly developed by Kisii University")
|
144 |
|
145 |
# Accept user input
|
146 |
if prompt := st.chat_input(f"Hi, I'm {selected_model}, let's chat"):
|
147 |
# Display user message in chat message container
|
148 |
-
st.
|
|
|
149 |
# Add user message to chat history
|
150 |
st.session_state.messages.append(("user", prompt))
|
151 |
|
@@ -154,15 +142,17 @@ if prompt := st.chat_input(f"Hi, I'm {selected_model}, let's chat"):
|
|
154 |
|
155 |
if assistant_response is not None:
|
156 |
# Display assistant response in chat message container
|
157 |
-
st.
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
#
|
163 |
-
if
|
164 |
-
|
165 |
-
|
|
|
|
|
166 |
|
167 |
# Add assistant response to chat history
|
168 |
st.session_state.messages.append(("assistant", assistant_response))
|
|
|
11 |
Resets Conversation
|
12 |
'''
|
13 |
st.session_state.messages = []
|
|
|
14 |
return None
|
15 |
|
16 |
def analyze_diagnosis(messages, model_link):
|
|
|
105 |
st.error(f"Error communicating with the API: {e}")
|
106 |
return None
|
107 |
|
108 |
+
# Initialize chat history
|
109 |
if "messages" not in st.session_state:
|
110 |
st.session_state.messages = []
|
|
|
111 |
|
112 |
# Create sidebar with model selection dropdown and reset button
|
113 |
selected_model = st.sidebar.selectbox("Select Model", list(model_links.keys()))
|
114 |
reset_button = st.sidebar.button('Reset Chat', on_click=reset_conversation)
|
115 |
|
116 |
# Add diagnostic feature to the sidebar
|
117 |
+
if len(st.session_state.messages) >= 3:
|
118 |
+
with st.sidebar.beta_container():
|
119 |
st.subheader("Diagnosis")
|
|
|
120 |
|
121 |
diagnosis = analyze_diagnosis(st.session_state.messages, model_links[selected_model])
|
122 |
if diagnosis:
|
123 |
+
st.write(diagnosis)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
|
125 |
# Add cautionary message about testing phase at the bottom of the sidebar
|
|
|
126 |
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.")
|
127 |
|
128 |
# Add logo and text to the sidebar
|
|
|
129 |
st.sidebar.image("https://assets.isu.pub/document-structure/221118065013-a6029cf3d563afaf9b946bb9497d45d4/v1/2841525b232adaef7bd0efe1da81a4c5.jpeg", width=200)
|
130 |
st.sidebar.write("A product proudly developed by Kisii University")
|
131 |
|
132 |
# Accept user input
|
133 |
if prompt := st.chat_input(f"Hi, I'm {selected_model}, let's chat"):
|
134 |
# Display user message in chat message container
|
135 |
+
with st.chat_message("user"):
|
136 |
+
st.markdown(prompt)
|
137 |
# Add user message to chat history
|
138 |
st.session_state.messages.append(("user", prompt))
|
139 |
|
|
|
142 |
|
143 |
if assistant_response is not None:
|
144 |
# Display assistant response in chat message container
|
145 |
+
with st.empty():
|
146 |
+
st.markdown("AI is typing...")
|
147 |
+
st.empty()
|
148 |
+
st.markdown(assistant_response)
|
149 |
+
|
150 |
+
# Check if intervention is needed based on bot response
|
151 |
+
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"]):
|
152 |
+
# Intervention logic here
|
153 |
+
if not st.session_state.ask_intervention:
|
154 |
+
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"):
|
155 |
+
st.write("You can reach out to a certified therapist at +25493609747.")
|
156 |
|
157 |
# Add assistant response to chat history
|
158 |
st.session_state.messages.append(("assistant", assistant_response))
|