ogegadavis254 commited on
Commit
4700e8c
1 Parent(s): 0114eb4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -46
app.py CHANGED
@@ -107,7 +107,13 @@ def interact_with_together_api(messages, model_link):
107
 
108
  # Create sidebar with model selection dropdown and reset button
109
  selected_model = st.sidebar.selectbox("Select Model", list(model_links.keys()))
110
- st.sidebar.button('Reset Chat', on_click=reset_conversation)
 
 
 
 
 
 
111
 
112
  # Add cautionary message about testing phase at the bottom of the sidebar
113
  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.")
@@ -115,48 +121,3 @@ st.sidebar.markdown("**Note**: This model is still in the beta phase. Responses
115
  # Add logo and text to the sidebar
116
  st.sidebar.image("https://assets.isu.pub/document-structure/221118065013-a6029cf3d563afaf9b946bb9497d45d4/v1/2841525b232adaef7bd0efe1da81a4c5.jpeg", width=200)
117
  st.sidebar.write("A product proudly developed by Kisii University")
118
-
119
- # Initialize chat history
120
- if "messages" not in st.session_state:
121
- st.session_state.messages = []
122
- st.session_state.message_count = 0
123
- st.session_state.ask_intervention = False
124
-
125
- # Display chat messages from history on app rerun
126
- for message in st.session_state.messages:
127
- with st.chat_message(message[0]):
128
- st.markdown(message[1])
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
- st.session_state.message_count += 1
138
-
139
- # Interact with the selected model
140
- assistant_response = interact_with_together_api(st.session_state.messages, model_links[selected_model])
141
-
142
- if assistant_response is not None:
143
- # Display assistant response in chat message container
144
- with st.empty():
145
- st.markdown("AI is typing...")
146
- st.empty()
147
- st.markdown(assistant_response)
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))
157
-
158
- # Add diagnostic feature to the sidebar
159
- diagnosis = analyze_diagnosis(st.session_state.messages, model_links[selected_model])
160
- if diagnosis:
161
- st.sidebar.subheader("Diagnosis")
162
- st.sidebar.write(diagnosis)
 
107
 
108
  # Create sidebar with model selection dropdown and reset button
109
  selected_model = st.sidebar.selectbox("Select Model", list(model_links.keys()))
110
+ reset_button = st.sidebar.button('Reset Chat', on_click=reset_conversation)
111
+
112
+ # Add diagnostic feature to the sidebar
113
+ diagnosis = analyze_diagnosis(st.session_state.messages, model_links[selected_model])
114
+ if diagnosis:
115
+ st.sidebar.subheader("Diagnosis")
116
+ st.sidebar.write(diagnosis)
117
 
118
  # Add cautionary message about testing phase at the bottom of the sidebar
119
  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.")
 
121
  # Add logo and text to the sidebar
122
  st.sidebar.image("https://assets.isu.pub/document-structure/221118065013-a6029cf3d563afaf9b946bb9497d45d4/v1/2841525b232adaef7bd0efe1da81a4c5.jpeg", width=200)
123
  st.sidebar.write("A product proudly developed by Kisii University")