# -*- coding: utf-8 -*- """app.ipynb Automatically generated by Colab. Original file is located at https://colab.research.google.com/drive/1eFgao8MF2-w0wFEdoXkd6vFRHYANPnrP """ import streamlit as st from utils import agent import folium from streamlit_folium import st_folium from utils import agent, find_clinics from datetime import datetime st.set_page_config(page_title="🧠 Mental Health Q&A Agent", layout="centered") # --- Header --- st.markdown("## πŸ’¬ Ask Your Mental Health Assistant") st.markdown("An AI-powered assistant to support your mental health questions using RAG + LLM") # --- Input Box with Placeholder --- user_question = st.text_input( "Ask a question:", placeholder="e.g. Why do I feel anxious before exams?" ) def render_clinic_map(clinics): if not clinics: st.warning("No clinics found to display.") return map_center = [clinics[0]["lat"], clinics[0]["lng"]] m = folium.Map(location=map_center, zoom_start=13) for clinic in clinics: folium.Marker( location=[clinic["lat"], clinic["lng"]], popup=f"{clinic['name']}
{clinic['address']}
{clinic['phone']}", tooltip=clinic["name"] ).add_to(m) st.markdown("### πŸ—ΊοΈ Map of Nearby Clinics") st_folium(m, width=700, height=500) # --- Session history setup --- if "history" not in st.session_state: st.session_state.history = [] # --- Processing user input --- # if user_question: # with st.spinner("πŸ€– Thinking..."): # try: # response = agent.run(user_question) # # Save Q&A to session history # st.session_state.history.append((user_question, response)) # # Display answer # st.markdown("### 🧠 Response:") # st.success(response) # st.caption(f"Answered on {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}") # except Exception as e: # st.error(f"An error occurred: {e}") if user_question: with st.spinner("πŸ€– Thinking..."): try: response = agent.run(user_question) # πŸ‘‰ Check if it's a clinic-related query if "clinic" in user_question.lower() or "hospital" in user_question.lower(): clinics = find_clinics(user_question) render_clinic_map(clinics) # Save Q&A to history st.session_state.history.append((user_question, response)) # Display text response st.markdown("### 🧠 Response:") st.success(response) st.caption(f"Answered on {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}") except Exception as e: st.error(f"An error occurred: {e}") # --- Show Previous Q&A --- if st.session_state.history: with st.expander("πŸ•˜ View Previous Questions"): for i, (q, a) in enumerate(reversed(st.session_state.history), 1): st.markdown(f"**Q{i}:** {q}") st.markdown(f"**A{i}:** {a}") st.markdown("---")