File size: 2,733 Bytes
136e149
3771a70
 
 
5420da2
 
3771a70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5420da2
 
 
 
 
 
 
3771a70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5420da2
 
 
 
 
 
 
3771a70
 
 
 
 
 
b1aeb5a
3771a70
b1aeb5a
 
 
 
 
 
 
 
 
5420da2
 
b1aeb5a
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# 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}")