Spaces:
Sleeping

memory-chatbot / app.py
Kumardba224's picture
Create app.py
0eed540 verified
Raw History Blame Contribute Delete
1.99 kB
import streamlit as st
from memory_backend import (
chat_with_memory
)
# -----------------------------------
# Page Config
# -----------------------------------
st.set_page_config(
page_title="AI Memory Chatbot",
page_icon="🧠",
layout="wide"
)
# -----------------------------------
# Title
# -----------------------------------
st.title("🧠 Day 9 - AI Memory Chatbot")
st.markdown("""
This chatbot remembers:
- previous messages
- conversation context
- follow-up discussions
""")
# -----------------------------------
# Session State
# -----------------------------------
if "messages" not in st.session_state:
st.session_state.messages = []
# -----------------------------------
# Display Chat History
# -----------------------------------
for msg in st.session_state.messages:
with st.chat_message(msg["role"]):
st.write(msg["content"])
# -----------------------------------
# User Input
# -----------------------------------
user_input = st.chat_input(
"Ask something..."
)
# -----------------------------------
# Chat Logic
# -----------------------------------
if user_input:
# Save user message
st.session_state.messages.append(
{
"role": "user",
"content": user_input
}
)
# Display user message
with st.chat_message("user"):
st.write(user_input)
# Generate response
with st.chat_message("assistant"):
with st.spinner("Thinking..."):
response = chat_with_memory(
user_input
)
st.write(response)
# Save assistant response
st.session_state.messages.append(
{
"role": "assistant",
"content": response
}
)
# -----------------------------------
# Sidebar
# -----------------------------------
with st.sidebar:
st.header("⚙️ Controls")
if st.button("Clear Chat"):
st.session_state.messages = []
st.rerun()