Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -22,6 +22,9 @@ if 'form_key' not in st.session_state:
|
|
22 |
# New variable for debouncing: whether processing is in progress
|
23 |
if 'is_processing' not in st.session_state:
|
24 |
st.session_state.is_processing = False
|
|
|
|
|
|
|
25 |
|
26 |
# THEN: Import your modules
|
27 |
from rag_engine import process_query, load_model
|
@@ -231,23 +234,26 @@ with col1:
|
|
231 |
with col2:
|
232 |
word_limit = st.slider("Word limit:", 50, 500, 200)
|
233 |
|
234 |
-
#
|
235 |
if st.session_state.submit_clicked and st.session_state.last_query:
|
236 |
st.session_state.submit_clicked = False
|
237 |
|
238 |
with st.spinner("Processing your question..."):
|
239 |
try:
|
240 |
result = process_query(st.session_state.last_query, top_k=top_k, word_limit=word_limit)
|
241 |
-
st.
|
242 |
-
st.write(result["answer_with_rag"])
|
243 |
-
st.subheader("Sources:")
|
244 |
-
for citation in result["citations"].split("\n"):
|
245 |
-
st.write(citation)
|
246 |
except Exception as e:
|
247 |
-
st.
|
248 |
-
# Reset debouncing after
|
249 |
st.session_state.is_processing = False
|
250 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
251 |
|
252 |
# Add helpful information
|
253 |
st.markdown("---")
|
|
|
22 |
# New variable for debouncing: whether processing is in progress
|
23 |
if 'is_processing' not in st.session_state:
|
24 |
st.session_state.is_processing = False
|
25 |
+
# Store the answer so that it persists on screen
|
26 |
+
if 'last_answer' not in st.session_state:
|
27 |
+
st.session_state.last_answer = None
|
28 |
|
29 |
# THEN: Import your modules
|
30 |
from rag_engine import process_query, load_model
|
|
|
234 |
with col2:
|
235 |
word_limit = st.slider("Word limit:", 50, 500, 200)
|
236 |
|
237 |
+
# Process the query only if explicitly submitted
|
238 |
if st.session_state.submit_clicked and st.session_state.last_query:
|
239 |
st.session_state.submit_clicked = False
|
240 |
|
241 |
with st.spinner("Processing your question..."):
|
242 |
try:
|
243 |
result = process_query(st.session_state.last_query, top_k=top_k, word_limit=word_limit)
|
244 |
+
st.session_state.last_answer = result # Store the result in session state
|
|
|
|
|
|
|
|
|
245 |
except Exception as e:
|
246 |
+
st.session_state.last_answer = {"answer_with_rag": f"Error processing query: {str(e)}", "citations": ""}
|
247 |
+
# Reset debouncing after processing
|
248 |
st.session_state.is_processing = False
|
249 |
+
|
250 |
+
# Display the answer if available
|
251 |
+
if st.session_state.last_answer is not None:
|
252 |
+
st.subheader("Answer:")
|
253 |
+
st.write(st.session_state.last_answer["answer_with_rag"])
|
254 |
+
st.subheader("Sources:")
|
255 |
+
for citation in st.session_state.last_answer["citations"].split("\n"):
|
256 |
+
st.write(citation)
|
257 |
|
258 |
# Add helpful information
|
259 |
st.markdown("---")
|