Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -17,10 +17,6 @@ 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 'should_clear_input' not in st.session_state:
|
21 |
-
st.session_state.should_clear_input = False
|
22 |
-
if 'current_input' not in st.session_state:
|
23 |
-
st.session_state.current_input = ""
|
24 |
|
25 |
# THEN: Import your modules
|
26 |
from rag_engine import process_query, load_model
|
@@ -97,26 +93,19 @@ elif st.session_state.init_time is not None:
|
|
97 |
init_message.empty()
|
98 |
st.session_state.init_time = None # Reset timer after clearing
|
99 |
|
100 |
-
#
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
st.session_state.submit_clicked = True
|
106 |
|
107 |
-
# Query input with callback for Enter key
|
108 |
-
query = st.text_input(
|
109 |
-
"Ask your question:",
|
110 |
-
key="query_input",
|
111 |
-
on_change=handle_submit if not st.session_state.should_clear_input else None
|
112 |
-
)
|
113 |
-
|
114 |
-
# Clear input if needed (after processing)
|
115 |
-
if st.session_state.should_clear_input:
|
116 |
-
# We can't modify the widget value directly, so we'll rerun with a blank value
|
117 |
-
st.session_state.should_clear_input = False
|
118 |
-
st.session_state.query_input = ""
|
119 |
-
|
120 |
# Display the current question if there is one
|
121 |
if st.session_state.last_query:
|
122 |
st.markdown("### Current Question:")
|
@@ -129,17 +118,9 @@ with col1:
|
|
129 |
with col2:
|
130 |
word_limit = st.slider("Word limit:", 50, 500, 200)
|
131 |
|
132 |
-
# Process button
|
133 |
-
if st.button("Get Answer"):
|
134 |
-
if st.session_state.query_input: # If there's text in the input field
|
135 |
-
st.session_state.last_query = st.session_state.query_input
|
136 |
-
st.session_state.should_clear_input = True
|
137 |
-
st.session_state.submit_clicked = True
|
138 |
-
# We'll clear the input on the next run
|
139 |
-
|
140 |
# Only process the query if explicitly submitted
|
141 |
if st.session_state.submit_clicked and st.session_state.last_query:
|
142 |
-
# Reset the submit flag
|
143 |
st.session_state.submit_clicked = False
|
144 |
|
145 |
# Process the 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 |
|
21 |
# THEN: Import your modules
|
22 |
from rag_engine import process_query, load_model
|
|
|
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 |
+
# Process form submission
|
105 |
+
if submit_button and query:
|
106 |
+
st.session_state.last_query = query
|
107 |
st.session_state.submit_clicked = True
|
108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
# Display the current question if there is one
|
110 |
if st.session_state.last_query:
|
111 |
st.markdown("### Current Question:")
|
|
|
118 |
with col2:
|
119 |
word_limit = st.slider("Word limit:", 50, 500, 200)
|
120 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
# Only process the query if explicitly submitted
|
122 |
if st.session_state.submit_clicked and st.session_state.last_query:
|
123 |
+
# Reset the submit flag
|
124 |
st.session_state.submit_clicked = False
|
125 |
|
126 |
# Process the query
|