Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -17,8 +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 |
|
23 |
# THEN: Import your modules
|
24 |
from rag_engine import process_query, load_model
|
@@ -69,8 +69,6 @@ if not st.session_state.initialized:
|
|
69 |
st.session_state.initialized = True
|
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 |
|
@@ -82,26 +80,17 @@ elif st.session_state.init_time is not 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 |
-
#
|
89 |
-
st.session_state.
|
90 |
|
91 |
-
# Create a form
|
92 |
-
with st.form(key="
|
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:
|
107 |
st.markdown("### Current Question:")
|
|
|
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_key' not in st.session_state:
|
21 |
+
st.session_state.form_key = 0 # This will help us reset the form
|
22 |
|
23 |
# THEN: Import your modules
|
24 |
from rag_engine import process_query, load_model
|
|
|
69 |
st.session_state.initialized = True
|
70 |
st.session_state.init_time = time.time()
|
71 |
init_message.success("System initialized successfully!")
|
|
|
|
|
72 |
except Exception as e:
|
73 |
init_message.error(f"Error initializing: {str(e)}")
|
74 |
|
|
|
80 |
|
81 |
# Function to handle form submission
|
82 |
def handle_form_submit():
|
83 |
+
if st.session_state.query_input and st.session_state.query_input.strip():
|
84 |
+
st.session_state.last_query = st.session_state.query_input.strip()
|
85 |
st.session_state.submit_clicked = True
|
86 |
+
# Increment the form key to force a reset
|
87 |
+
st.session_state.form_key += 1
|
88 |
|
89 |
+
# Create a form with dynamic key for resetting
|
90 |
+
with st.form(key=f"query_form_{st.session_state.form_key}"):
|
91 |
query = st.text_input("Ask your question:", key="query_input", placeholder="Press enter to submit question")
|
92 |
submit_button = st.form_submit_button("Get Answer", on_click=handle_form_submit)
|
93 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
# Display the current question if there is one
|
95 |
if st.session_state.last_query:
|
96 |
st.markdown("### Current Question:")
|