Create app.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051import streamlit as stfrom backend import generate_response
# Streamlit Page Configurationst.set_page_config(page_title="College Chatbot", layout="centered")st.title("🎓 CBIT Engineering College (Pallavolu) Chatbot")
# Sidebar for User Type Selectionuser_type = st.sidebar.selectbox( "Select User Type", ["Student", "Parent", "General Public"])
# Initialize Chat History and session state variablesif "chat_history" not in st.session_state: st.session_state.chat_history = []if "user_input" not in st.session_state: st.session_state.user_input = ""if "should_clear_input" not in st.session_state: st.session_state.should_clear_input = False
# Clear input if flag is setif st.session_state.should_clear_input: st.session_state.user_input = "" st.session_state.should_clear_input = False
# Form for handling input submissionwith st.form(key="chat_form"): user_query = st.text_input( "Ask me anything about the college...", value=st.session_state.user_input, key="user_input" ) submit_button = st.form_submit_button("Send")
if submit_button and user_query: # Generate Response bot_response = generate_response(user_query, user_type.lower())
# Store chat history st.session_state.chat_history.append(("You", user_query)) st.session_state.chat_history.append(("Chatbot", bot_response))
# Set flag to clear input and rerun st.session_state.should_clear_input = True st.rerun()
# Display Chat History in Reverse Orderst.subheader("Chat History")for role, message in reversed(st.session_state.chat_history): with st.chat_message(role): st.markdown(message)app.pyAdded+51