Spaces:
Sleeping
Sleeping
ogegadavis254
commited on
Commit
•
9e4c880
1
Parent(s):
6e2a9c8
Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,6 @@ import requests
|
|
3 |
import os
|
4 |
from dotenv import load_dotenv
|
5 |
from requests.exceptions import RequestException
|
6 |
-
import time
|
7 |
|
8 |
load_dotenv()
|
9 |
|
@@ -77,10 +76,7 @@ def interact_with_together_api(messages, model_link):
|
|
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 |
-
if st.session_state.get('selected_model') != selected_model:
|
82 |
-
st.session_state.selected_model = selected_model
|
83 |
-
st.info(f"You have switched to {selected_model}.")
|
84 |
st.sidebar.button('Reset Chat', on_click=reset_conversation)
|
85 |
|
86 |
# Add cautionary message about testing phase at the bottom of the sidebar
|
@@ -110,28 +106,21 @@ if prompt := st.chat_input(f"Hi, I'm {selected_model}, let's chat"):
|
|
110 |
st.session_state.messages.append(("user", prompt))
|
111 |
st.session_state.message_count += 1
|
112 |
|
113 |
-
# Simulate typing
|
114 |
-
with st.empty():
|
115 |
-
st.markdown("AI is typing...")
|
116 |
-
time.sleep(0.5)
|
117 |
-
st.empty()
|
118 |
-
st.markdown("AI is typing...")
|
119 |
-
time.sleep(0.5)
|
120 |
-
st.empty()
|
121 |
-
st.markdown("AI is typing...")
|
122 |
-
time.sleep(0.5)
|
123 |
-
|
124 |
# Interact with the selected model
|
125 |
assistant_response = interact_with_together_api(st.session_state.messages, model_links[selected_model])
|
126 |
|
127 |
if assistant_response is not None:
|
128 |
# Display assistant response in chat message container
|
129 |
-
with st.
|
|
|
|
|
130 |
st.markdown(assistant_response)
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
|
132 |
-
#
|
133 |
-
|
134 |
-
# Intervention logic here
|
135 |
-
if not st.session_state.ask_intervention:
|
136 |
-
if st.button("After 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"):
|
137 |
-
st.write("You can reach out to a certified therapist at +25493609747.")
|
|
|
3 |
import os
|
4 |
from dotenv import load_dotenv
|
5 |
from requests.exceptions import RequestException
|
|
|
6 |
|
7 |
load_dotenv()
|
8 |
|
|
|
76 |
return None
|
77 |
|
78 |
# Create sidebar with model selection dropdown and reset button
|
79 |
+
selected_model = st.sidebar.selectbox("Select Model", list(model_links.keys()))
|
|
|
|
|
|
|
80 |
st.sidebar.button('Reset Chat', on_click=reset_conversation)
|
81 |
|
82 |
# Add cautionary message about testing phase at the bottom of the sidebar
|
|
|
106 |
st.session_state.messages.append(("user", prompt))
|
107 |
st.session_state.message_count += 1
|
108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
# Interact with the selected model
|
110 |
assistant_response = interact_with_together_api(st.session_state.messages, model_links[selected_model])
|
111 |
|
112 |
if assistant_response is not None:
|
113 |
# Display assistant response in chat message container
|
114 |
+
with st.empty():
|
115 |
+
st.markdown("AI is typing...")
|
116 |
+
st.empty()
|
117 |
st.markdown(assistant_response)
|
118 |
+
# Check if intervention is needed based on bot response
|
119 |
+
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"]):
|
120 |
+
# Intervention logic here
|
121 |
+
if not st.session_state.ask_intervention:
|
122 |
+
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"):
|
123 |
+
st.write("You can reach out to a certified therapist at +25493609747.")
|
124 |
|
125 |
+
# Add assistant response to chat history
|
126 |
+
st.session_state.messages.append(("assistant", assistant_response))
|
|
|
|
|
|
|
|