Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -93,18 +93,29 @@ elif st.session_state.init_time is not None:
|
|
93 |
init_message.empty()
|
94 |
st.session_state.init_time = None # Reset timer after clearing
|
95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
# Create a form for handling the user input
|
97 |
with st.form(key="query_form"):
|
98 |
# Put the input inside the form
|
99 |
-
query = st.text_input("Ask your question:", key="query_input")
|
100 |
|
101 |
# Submit button within the form
|
102 |
-
submit_button = st.form_submit_button("Get Answer")
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
|
109 |
# Display the current question if there is one
|
110 |
if st.session_state.last_query:
|
|
|
93 |
init_message.empty()
|
94 |
st.session_state.init_time = None # Reset timer after clearing
|
95 |
|
96 |
+
# Handle form submission - this ensures input is cleared and focus is removed
|
97 |
+
if 'form_submitted' not in st.session_state:
|
98 |
+
st.session_state.form_submitted = False
|
99 |
+
|
100 |
+
# Function to handle form submission
|
101 |
+
def handle_form_submit():
|
102 |
+
if st.session_state.query_input:
|
103 |
+
st.session_state.last_query = st.session_state.query_input
|
104 |
+
st.session_state.submit_clicked = True
|
105 |
+
st.session_state.form_submitted = True
|
106 |
+
|
107 |
# Create a form for handling the user input
|
108 |
with st.form(key="query_form"):
|
109 |
# Put the input inside the form
|
110 |
+
query = st.text_input("Ask your question:", key="query_input", value="")
|
111 |
|
112 |
# Submit button within the form
|
113 |
+
submit_button = st.form_submit_button("Get Answer", on_click=handle_form_submit)
|
114 |
+
|
115 |
+
# Force a rerun after form submission to reset the input field and focus
|
116 |
+
if st.session_state.form_submitted:
|
117 |
+
st.session_state.form_submitted = False
|
118 |
+
st.rerun()
|
119 |
|
120 |
# Display the current question if there is one
|
121 |
if st.session_state.last_query:
|