ankanghosh commited on
Commit
226da61
·
verified ·
1 Parent(s): 8bfb7cc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -9
app.py CHANGED
@@ -1,4 +1,5 @@
1
  import streamlit as st
 
2
 
3
  # FIRST: Set page config before ANY other Streamlit command
4
  st.set_page_config(page_title="Indian Spiritual RAG")
@@ -54,25 +55,30 @@ if not st.session_state.initialized:
54
  # Preload the model to avoid session state issues
55
  if not st.session_state.initialized:
56
  try:
57
- with st.spinner("Hang in there! We are setting the system up for you. 😊"):
58
- # Force model loading at startup to avoid session state issues
59
- load_model()
60
- st.session_state.initialized = True
61
- st.success("System initialized successfully!")
 
 
 
 
 
62
  except Exception as e:
63
  st.error(f"Error initializing: {str(e)}")
64
 
65
  # Function to process when enter is pressed or button is clicked
66
  def process_input():
67
- st.session_state.last_query = st.session_state.query
68
- st.session_state.query = ""
69
  st.session_state.submit_clicked = True
70
 
71
  # Query input with callback for Enter key
72
  query = st.text_input(
73
  "Ask your question:",
74
- key="query",
75
- on_change=process_input if st.session_state.query and st.session_state.query.strip() else None
76
  )
77
 
78
  # Display the current question if there is one
 
1
  import streamlit as st
2
+ import time
3
 
4
  # FIRST: Set page config before ANY other Streamlit command
5
  st.set_page_config(page_title="Indian Spiritual RAG")
 
55
  # Preload the model to avoid session state issues
56
  if not st.session_state.initialized:
57
  try:
58
+ init_message = st.empty()
59
+ init_message.info("Hang in there! We are setting the system up for you. 😊")
60
+
61
+ # Force model loading at startup to avoid session state issues
62
+ load_model()
63
+
64
+ # Keep the message for 2 seconds before replacing it
65
+ time.sleep(2)
66
+ init_message.success("System initialized successfully!")
67
+ st.session_state.initialized = True
68
  except Exception as e:
69
  st.error(f"Error initializing: {str(e)}")
70
 
71
  # Function to process when enter is pressed or button is clicked
72
  def process_input():
73
+ st.session_state.last_query = st.session_state.query_input
74
+ st.session_state.query_input = ""
75
  st.session_state.submit_clicked = True
76
 
77
  # Query input with callback for Enter key
78
  query = st.text_input(
79
  "Ask your question:",
80
+ key="query_input",
81
+ on_change=process_input
82
  )
83
 
84
  # Display the current question if there is one