from statistics import mode import streamlit as st import logging from PIL import Image, ImageEnhance import base64 from groq import Groq import urllib import os logging.basicConfig(level=logging.INFO) api_key = os.getenv("OPENAI_API_KEY") client = Groq(api_key=api_key) st.set_page_config( page_title="app.py", page_icon="imgs/avatar_streamly.png", layout="wide", initial_sidebar_state="auto", ) st.markdown( """ """, unsafe_allow_html=True ) st.markdown('
TALK TO YOUR AI THERAPIST
""", unsafe_allow_html=True ) # st.write("### Real Time Live Therapy Session") # In-progress message st.markdown( """ """, unsafe_allow_html=True ) # Simulate real-time communication # st.write("### Real Time Live Therapy Session") # Initialize location input field location = "" # Location input based on mode if "mode" in st.session_state and st.session_state["mode"] == "Visit Doctor": st.markdown( """ """, unsafe_allow_html=True ) st.markdown( f"""THERAPIST OR DOCTOR NEAR ME {location.strip()}
""", unsafe_allow_html=True ) # location = st.chat_input("Enter your location here...") # if location: # st.session_state.user_details["location"] = location # if location.strip(): # google_maps_link = f"https://www.google.com/maps/search/{urllib.parse.quote('therapists or hospitals near ' + location)}" # st.markdown(f"Find a licensed therapist or doctor near **{location}**: [Click here to view on Google Maps]({google_maps_link})") # Initialize session state for storing chat messages if "messages" not in st.session_state: st.session_state["messages"] = [] user_avatar = "imgs/googlemap.png" assistant_avatar = "imgs/botreq.png" # Chat input field for location location = st.chat_input("Enter your location here...") # Process input if available if location: # Save user's location input st.session_state["messages"].append({"role": "user", "content": location}) # Generate Google Maps link and add it as assistant's response if location.strip(): google_maps_link = f"https://www.google.com/maps/search/{urllib.parse.quote('therapists or hospitals near ' + location)}" bot_reply = f"Find a licensed therapist or doctor near **{location}**: [Click here to view on Google Maps]({google_maps_link})" st.session_state["messages"].append({"role": "assistant", "content": bot_reply}) # Display chat history with avatars for user and assistant for message in st.session_state["messages"]: role = message["role"] avatar_image = assistant_avatar if role == "assistant" else user_avatar with st.chat_message(role.capitalize(), avatar=avatar_image): st.write(message["content"]) show_basic_info = st.sidebar.checkbox("Quick Chat ", value=False) if show_basic_info: st.sidebar.markdown(""" ### Quick Chat Guidance - **Share Your Feelings**: Express what you're feeling, like "I'm stressed" or "I'm overwhelmed." - **How to Respond**: The AI will listen and offer support. Share more if you wish. - **Be Open**: Take your time and talk about what's on your mind. - **Ask for Help**: If unsure, say "I need help with stress" and the AI will guide you. """) show_advanced_info = st.sidebar.checkbox("Comprehensive Guidance", value=False) if show_advanced_info: st.sidebar.markdown(""" ### Comprehensive Guidance - **Mental Health**: - "Seeking help is a sign of strength. Small steps matter." - "Therapists can guide you through tough times." - "You deserve to feel better." - **When to Seek Help**: - "Feeling overwhelmed? A therapist can support you." - "Reach out to a doctor if mental health feels too much." """) if mode == "Chat with Therapist": if not st.session_state.conversation_history: initialize_conversation() chat_input1 = st.chat_input("Type your message here...") if chat_input1: on_chat_submit(chat_input1) for message in st.session_state.conversation_history[-10:]: role = message["role"] avatar_image = "imgs/avatar_streamly.png" if role == "assistant" else "imgs/stuser.png" with st.chat_message(role.capitalize(), avatar=avatar_image): st.write(message["content"]) if __name__ == "__main__": main()