File size: 1,076 Bytes
8c6e3b3
 
 
 
a7f05d9
8c6e3b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a7f05d9
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
# alfred_streamlit.py
import streamlit as st
from langchain_core.messages import HumanMessage
from tools import alfred  # Import your LangGraph agent
#
st.set_page_config(page_title="🕵️ Alfred - AI Assistant", page_icon="🎩")

st.title("🎩 Alfred - Your AI Assistant")
st.markdown("Ask Alfred anything. He’s connected to weather, search, model stats, and even your guest list!")

if "chat_history" not in st.session_state:
    st.session_state.chat_history = []

# Chat input
user_input = st.chat_input("Ask Alfred...")

if user_input:
    st.session_state.chat_history.append(HumanMessage(content=user_input))
    with st.spinner("Alfred is thinking..."):
        response = alfred.invoke({"messages": st.session_state.chat_history})
        ai_response = response['messages'][-1].content
        st.session_state.chat_history.append(response['messages'][-1])

# Display chat history
for msg in st.session_state.chat_history:
    role = "🤵 Alfred" if msg.type == "ai" else "🧑 You"
    st.chat_message(role).markdown(msg.content)