# Force redeploy trigger - version 1.1 import streamlit as st from utils.config import config import requests import json from core.memory import load_user_state # Set page config st.set_page_config(page_title="AI Life Coach", page_icon="🧘", layout="centered") # Sidebar for user selection st.sidebar.title("🧘 AI Life Coach") user = st.sidebar.selectbox("Select User", ["Rob", "Sarah"]) st.sidebar.markdown("---") # Fetch Ollama status def get_ollama_status(): try: response = requests.get("http://localhost:8000/api/ollama-status") if response.status_code == 200: return response.json() except Exception: return {"running": False, "model_loaded": None} # After user selects name, load conversation history def get_conversation_history(user_id): user_state = load_user_state(user_id) if user_state and "conversation" in user_state: return json.loads(user_state["conversation"]) return [] ollama_status = get_ollama_status() # Display Ollama status if ollama_status["running"]: st.sidebar.success(f"🧠 Model Running: {ollama_status['model_loaded']}") else: st.sidebar.error("🧠 Ollama is not running or no model loaded.") # Main chat interface st.title("🧘 AI Life Coach") st.markdown("Talk to your personal development assistant.") if not ollama_status["running"]: st.warning("⚠️ Ollama is not running. Please start Ollama to use the AI Life Coach.") else: # Display conversation history conversation = get_conversation_history(user) for msg in conversation: role = msg["role"].capitalize() content = msg["content"] st.markdown(f"**{role}:** {content}") # Chat input user_input = st.text_input("Your message...", key="input") if st.button("Send"): if user_input.strip() == "": st.warning("Please enter a message.") else: # Display user message st.markdown(f"**You:** {user_input}") # Send to backend with st.spinner("AI Coach is thinking..."): try: response = requests.post( "http://localhost:8000/api/chat", json={"user_id": user, "message": user_input} ) if response.status_code == 200: response_data = response.json() ai_response = response_data.get("response", "") st.markdown(f"**AI Coach:** {ai_response}") else: st.error("Failed to get response from AI Coach.") except Exception as e: st.error(f"Connection error: {e}")