File size: 1,635 Bytes
d7f9105 |
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 |
import streamlit as st
from src import utils
from src.llm import EmotionalChatbot
from src.log import logger
# Streamlit UI Setup
st.set_page_config(
page_title="Emotional Intelligence Bot",
page_icon="π€",
layout="wide"
)
# Initialize session state for chat history
if "chat_history" not in st.session_state:
st.session_state.chat_history = []
try:
# Initialize the chatbot
chatbot = EmotionalChatbot(chat_history=st.session_state.chat_history)
except Exception as e:
logger.critical("Failed to initialize the chatbot", exc_info=True)
st.error("Unable to initialize the bot. Check logs for more details.")
st.markdown(utils.styles(), unsafe_allow_html=True)
st.header(":rainbow[Lumina] - :blue[EI Bot] π€")
st.sidebar.markdown(utils.sidebar_markdown())
# Display chat history
for message in st.session_state.chat_history:
for role, content in message.items():
with st.chat_message(role):
st.write(content)
# User input
user_input = st.chat_input("Chat With Lumina...")
if user_input:
with st.chat_message("user"):
st.write(user_input)
# Process the user input and generate bot response
try:
with st.spinner("Thinking..."):
response = chatbot.generate_response(user_input)
message = {'human':user_input, 'AI':response}
st.session_state.chat_history.append(message)
with st.chat_message("assistant"):
st.write(response)
except Exception as e:
logger.error(f"Error generating bot response: {e}")
st.error("An error occurred. Check logs for more details.")
|