├── requirements.txt ├── .gitattributes ├── README.md ├── LICENSE └── streamlit_app.py /requirements.txt: -------------------------------------------------------------------------------- 1 | cohere 2 | streamlit 3 | 4 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Kriyeta 3.0 (National Level Hackathon-Sponsored By DSIR) 2 | Kriyeta 3.0 Submission Round 3 | 4 | Project currently live at -: 5 | 6 | https://all-n-beyond.streamlit.app/ 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 aniket-2003-das 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /streamlit_app.py: -------------------------------------------------------------------------------- 1 | import cohere 2 | import streamlit as st 3 | 4 | co = cohere.Client('Uwedgi2WjbUKoOvU9OEcqU20Th3dO2HkXwDLafmZ') # This is your trial API key 5 | 6 | import uuid 7 | conversation_id = str(uuid.uuid4()) 8 | 9 | st.set_page_config(page_title="Ranjan - Mental Health Assistant") 10 | st.title("Mental Health Bot") 11 | 12 | preamble_prompt = """You are Ranjan, an AI mental health assistant designed to monitor patients and provide them support resources for emotional well-being. 13 | Your primary goal is to create a non-judgmental space for users to express their feelings and concerns. 14 | Actively listen, offer empathetic responses, and encourage self-reflection with positive coping strategies. 15 | Maintain user privacy and confidentiality throughout the interaction. 16 | If the user expresses self-harm or harm to others, prioritize safety by encouraging professional help or emergency services. 17 | 18 | Interaction Flow: 19 | Initial Greeting: 20 | Introduce yourself as Ranjan, the AI mental health assistant. 21 | Invite the user to share what's on their mind. 22 | 23 | Understanding and Strategies: 24 | Once the user expresses their concerns, offer relevant cognitive behavioral therapy (CBT) techniques or other self-help strategies. 25 | Focus on techniques that can help manage negative thoughts, improve mood, and develop healthy coping mechanisms. 26 | 27 | Professional Help Assessment: 28 | After exploring self-help strategies, gently inquire if they've considered seeking professional help from a therapist. 29 | Emphasize the value of additional support and personalized tools that a therapist can provide. 30 | 31 | Therapist Connection: 32 | If the user shows interest in finding a therapist, explain that you can help and request their details like location. 33 | To assist with finding a therapist, request additional information (with complete privacy): 34 | Location (city or state) 35 | Preferred therapy style (e.g., CBT, mindfulness) 36 | Insurance information (optional) 37 | 38 | Matching & Disclaimer: 39 | Based on the provided information, generate contact details for therapists in their area and provide it to them. 40 | 41 | Always Here to Listen: 42 | Reiterate your role as a listening ear and supportive resource, even if they aren't ready for a therapist. 43 | Express your desire to collaborate and support them in building emotional resilience.""" 44 | 45 | 46 | docs = [ 47 | { 48 | "title": "Ranjan - Mental Health Assistant", 49 | "snippet": "Ranjan is a compassionate and understanding virtual companion designed to monitor and provide a safe haven for individuals seeking support and guidance on their mental health journey. With a focus on creating a non-judgmental space, this chatbot actively listens to your thoughts, feelings, and concerns, offering empathetic responses and thoughtful insights.", 50 | }, 51 | ] 52 | 53 | 54 | def cohereReply(prompt): 55 | 56 | # Extract unique roles using a set 57 | unique_roles = set(item['role'] for item in st.session_state.messages) 58 | 59 | if {'USER', 'assistant'} <= unique_roles: 60 | # st.write("INITIAL_________________") 61 | llm_response = co.chat( 62 | message=prompt, 63 | documents=docs, 64 | model='command', 65 | preamble=preamble_prompt, 66 | conversation_id=conversation_id, 67 | #chat_history=st.session_state.messages, 68 | ) 69 | else: 70 | 71 | llm_response = co.chat( 72 | message=prompt, 73 | documents=docs, 74 | model='command', 75 | conversation_id=conversation_id, 76 | preamble=preamble_prompt, 77 | 78 | ) 79 | 80 | print(llm_response) 81 | return llm_response.text 82 | 83 | 84 | def initiailize_state(): 85 | # Initialize chat history 86 | if "messages" not in st.session_state: 87 | st.session_state.messages = [] 88 | 89 | 90 | def main(): 91 | 92 | initiailize_state() 93 | # Display chat messages from history on app rerun 94 | for message in st.session_state.messages: 95 | with st.chat_message(message["role"]): 96 | st.markdown(message["message"]) 97 | 98 | # React to user input 99 | if prompt := st.chat_input("What is up?"): 100 | # Display user message in chat message container 101 | st.chat_message("USER").markdown(prompt) 102 | # Add user message to chat history 103 | st.session_state.messages.append({"role": "USER", "message": prompt}) 104 | # print(st.session_state.messages) 105 | 106 | llm_reponse = cohereReply(prompt) 107 | with st.chat_message("assistant"): 108 | st.markdown(llm_reponse) 109 | st.session_state.messages.append( 110 | {"role": "assistant", "message": llm_reponse}) 111 | 112 | 113 | 114 | 115 | if __name__ == "__main__": 116 | main() 117 | --------------------------------------------------------------------------------