Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -17,10 +17,8 @@ if 'submit_clicked' not in st.session_state:
|
|
17 |
st.session_state.submit_clicked = False
|
18 |
if 'init_time' not in st.session_state:
|
19 |
st.session_state.init_time = None
|
20 |
-
if '
|
21 |
-
st.session_state.
|
22 |
-
if 'init_needs_rerun' not in st.session_state:
|
23 |
-
st.session_state.init_needs_rerun = False
|
24 |
|
25 |
# THEN: Import your modules
|
26 |
from rag_engine import process_query, load_model
|
@@ -72,7 +70,7 @@ if not st.session_state.initialized:
|
|
72 |
st.session_state.init_time = time.time()
|
73 |
init_message.success("System initialized successfully!")
|
74 |
time.sleep(0.1)
|
75 |
-
st.
|
76 |
except Exception as e:
|
77 |
init_message.error(f"Error initializing: {str(e)}")
|
78 |
|
@@ -82,28 +80,27 @@ elif st.session_state.init_time is not None:
|
|
82 |
init_message.empty()
|
83 |
st.session_state.init_time = None
|
84 |
|
85 |
-
#
|
86 |
-
if st.session_state.init_needs_rerun:
|
87 |
-
st.session_state.init_needs_rerun = False
|
88 |
-
st.rerun()
|
89 |
-
|
90 |
-
# Handle form submission
|
91 |
def handle_form_submit():
|
92 |
if st.session_state.query_input:
|
93 |
st.session_state.last_query = st.session_state.query_input
|
94 |
st.session_state.submit_clicked = True
|
95 |
-
|
96 |
-
st.session_state.
|
97 |
|
98 |
# Create a form for handling the user input
|
99 |
with st.form(key="query_form"):
|
100 |
query = st.text_input("Ask your question:", key="query_input", placeholder="Press enter to submit question")
|
101 |
submit_button = st.form_submit_button("Get Answer", on_click=handle_form_submit)
|
102 |
|
103 |
-
#
|
104 |
-
if st.session_state.
|
105 |
-
|
106 |
-
st.
|
|
|
|
|
|
|
|
|
107 |
|
108 |
# Display the current question if there is one
|
109 |
if st.session_state.last_query:
|
|
|
17 |
st.session_state.submit_clicked = False
|
18 |
if 'init_time' not in st.session_state:
|
19 |
st.session_state.init_time = None
|
20 |
+
if 'form_submitted' not in st.session_state:
|
21 |
+
st.session_state.form_submitted = False
|
|
|
|
|
22 |
|
23 |
# THEN: Import your modules
|
24 |
from rag_engine import process_query, load_model
|
|
|
70 |
st.session_state.init_time = time.time()
|
71 |
init_message.success("System initialized successfully!")
|
72 |
time.sleep(0.1)
|
73 |
+
st.experimental_rerun() # For compatibility with older Streamlit versions
|
74 |
except Exception as e:
|
75 |
init_message.error(f"Error initializing: {str(e)}")
|
76 |
|
|
|
80 |
init_message.empty()
|
81 |
st.session_state.init_time = None
|
82 |
|
83 |
+
# Function to handle form submission
|
|
|
|
|
|
|
|
|
|
|
84 |
def handle_form_submit():
|
85 |
if st.session_state.query_input:
|
86 |
st.session_state.last_query = st.session_state.query_input
|
87 |
st.session_state.submit_clicked = True
|
88 |
+
# Set form_submitted to True to trigger rerun
|
89 |
+
st.session_state.form_submitted = True
|
90 |
|
91 |
# Create a form for handling the user input
|
92 |
with st.form(key="query_form"):
|
93 |
query = st.text_input("Ask your question:", key="query_input", placeholder="Press enter to submit question")
|
94 |
submit_button = st.form_submit_button("Get Answer", on_click=handle_form_submit)
|
95 |
|
96 |
+
# Check if form was submitted and handle the rerun outside the callback
|
97 |
+
if st.session_state.form_submitted:
|
98 |
+
# Reset the flag
|
99 |
+
st.session_state.form_submitted = False
|
100 |
+
# Clear the input
|
101 |
+
st.session_state.query_input = ""
|
102 |
+
# Force a rerun to update the UI
|
103 |
+
st.experimental_rerun()
|
104 |
|
105 |
# Display the current question if there is one
|
106 |
if st.session_state.last_query:
|