Kumardba224's picture
Update app.py
73e774f verified
Raw History Blame Contribute Delete
1.86 kB
import streamlit as st
from agent_backend import ask_agent
# -----------------------------------
# Page config
# -----------------------------------
st.set_page_config(
page_title="Day 7 AI Agent",
page_icon="🤖",
layout="wide"
)
# -----------------------------------
# Title
# -----------------------------------
st.title("🤖 Day 7 - AI Agent Assistant")
st.markdown("""
This AI Agent can:
- 🧮 Perform calculations
- 🌐 Search the web
- 🧠 Reason using tools
""")
# -----------------------------------
# Sidebar
# -----------------------------------
with st.sidebar:
st.header("⚙️ Controls")
if st.button("🗑️ Clear Chat"):
st.session_state.messages = []
st.rerun()
# -----------------------------------
# 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 anything..."
)
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)
# assistant response
with st.chat_message("assistant"):
with st.spinner("Thinking..."):
response = ask_agent(user_input)
st.write(response)
# save assistant response
st.session_state.messages.append(
{
"role": "assistant",
"content": response
}
)