import streamlit as st from node import LibrarySystem from helper import response_generator from helper import send_message library = LibrarySystem() # Streamed response emulator st.set_page_config( page_title="🤗💬 Ana", layout="wide" ) st.warning('This is a prototype of a chatbot for Group 28 main algorithm. It is still under development even though the main logic has been completed and run inside terminal', icon="⚠️") st.caption("A Project done by Group 28") # Initialize chat history if "messages" not in st.session_state: st.session_state.messages = [{"role": "assistant", "content": "Let's start chatting! 👇. You can start with hello or hi"}] if 'app_state' not in st.session_state: st.session_state['app_state'] = 'initial' if 'book' not in st.session_state: st.session_state['book'] = None if 'user' not in st.session_state: st.session_state['user'] = '' with st.sidebar: st.title('🤗💬 Ana') st.markdown('📖 Ana is a library management and book recommendation app designed to enhance accessibility and convenience.') st.markdown('Convenient Access – Users can interact with Ana anytime, anywhere, to access library services from their comfort zones.') st.markdown('Smart Book Borrowing – Users can reserve books and pick them up at their convenience, eliminating scheduling conflicts.') st.markdown('Personalized Recommendations – The system suggests books based on user preferences, enhancing the reading experience.') # Display chat messages from history on app rerun for message in st.session_state.messages: with st.chat_message(message["role"]): st.markdown(message["content"]) # Accept user input if prompt := st.chat_input("What is up?"): #initialize library system object # Add user message to chat history st.session_state.messages.append({"role": "user", "content": prompt}) # Display user message in chat message container with st.chat_message("user"): st.markdown(prompt) # Display assistant response in chat message container with st.chat_message("assistant"): # with st.spinner("Thinking..."): if prompt.lower() in ["hi", "hello", "hey", "/start"]: data = library.startMessage() elif st.session_state['app_state'] == 'welcome' : data = library.login_or_register(prompt) elif st.session_state['app_state'] == 'login_search': data = library.loginSearch(prompt) elif st.session_state['app_state'] == 'waiting_for_name' or st.session_state['app_state'] == 'waiting_for_id' : data = library.handle_registration_input(prompt) elif st.session_state['app_state'] == 'default': data = library.main_menu(prompt) elif st.session_state['app_state'] == 'search': data = library.fetchbook(prompt) elif st.session_state['app_state'] == 'borrow': data = library.hasborrowed(st.session_state['book'], prompt) elif st.session_state['app_state'] == 'borrowing': library.borrow_book() else: send_message("Invalid input. Please try again.") # Add assistant response to chat history