Update src/streamlit_app.py

#2
Files changed (1) hide show
  1. src/streamlit_app.py +16 -2
src/streamlit_app.py CHANGED
@@ -92,15 +92,29 @@ st.set_page_config(page_title="Campus Helper Bot", page_icon="🤖")
92
  st.title("🤖 Campus Helper Bot")
93
  st.caption("Your AI-powered guide, now connected to Notion!")
94
 
 
 
 
 
 
 
 
 
 
95
  if "messages" not in st.session_state:
96
  st.session_state.messages = [
97
- {"role": "assistant", "content": "Hello! I'm now connected to a live Notion database. How can I help?"}
 
 
 
98
  ]
99
 
 
100
  for message in st.session_state.messages:
101
  with st.chat_message(message["role"]):
102
  st.markdown(message["content"])
103
 
 
104
  if prompt := st.chat_input("Ask about fee deadlines, scholarships, etc."):
105
  st.session_state.messages.append({"role": "user", "content": prompt})
106
  with st.chat_message("user"):
@@ -111,4 +125,4 @@ if prompt := st.chat_input("Ask about fee deadlines, scholarships, etc."):
111
  context = get_context(prompt)
112
  response = generate_response(prompt, context)
113
  st.markdown(response)
114
- st.session_state.messages.append({"role": "assistant", "content": response})
 
92
  st.title("🤖 Campus Helper Bot")
93
  st.caption("Your AI-powered guide, now connected to Notion!")
94
 
95
+ # --- 1. Fetch Notion data first ---
96
+ notion_data = fetch_notion_database()
97
+
98
+ # If Notion failed to load or is empty, stop the app
99
+ if not notion_data:
100
+ st.warning("⚠️ Notion database is empty or failed to load. Please check your API keys and database.")
101
+ st.stop()
102
+
103
+ # --- 2. Initialize chat session state ---
104
  if "messages" not in st.session_state:
105
  st.session_state.messages = [
106
+ {
107
+ "role": "assistant",
108
+ "content": "Hello! How can I help you today?" # You can change this freely now
109
+ }
110
  ]
111
 
112
+ # --- 3. Display existing messages ---
113
  for message in st.session_state.messages:
114
  with st.chat_message(message["role"]):
115
  st.markdown(message["content"])
116
 
117
+ # --- 4. Handle new user input ---
118
  if prompt := st.chat_input("Ask about fee deadlines, scholarships, etc."):
119
  st.session_state.messages.append({"role": "user", "content": prompt})
120
  with st.chat_message("user"):
 
125
  context = get_context(prompt)
126
  response = generate_response(prompt, context)
127
  st.markdown(response)
128
+ st.session_state.messages.append({"role": "assistant", "content": response})