Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -36,49 +36,44 @@ if 'page_loaded' not in st.session_state:
|
|
36 |
st.session_state.last_query = ""
|
37 |
st.session_state.last_answer = None
|
38 |
|
39 |
-
# Add
|
40 |
-
if '
|
41 |
-
|
42 |
-
# Generate a unique ID for this page load
|
43 |
-
st.session_state.page_visit_id = str(uuid.uuid4())
|
44 |
|
45 |
-
#
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
components.html(
|
48 |
-
|
49 |
<script>
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
// Store current ID for next time
|
66 |
-
localStorage.setItem('lastVisitId', currentVisitId);
|
67 |
-
|
68 |
-
// Listen for navigation away from the page
|
69 |
-
window.addEventListener('beforeunload', function() {{
|
70 |
-
// When navigating away, we want to be able to detect return
|
71 |
-
localStorage.setItem('navigatedAway', 'true');
|
72 |
-
}});
|
73 |
-
}})();
|
74 |
</script>
|
75 |
""",
|
76 |
height=0
|
77 |
)
|
78 |
|
79 |
-
# Call this function early in your script
|
80 |
-
setup_navigation_detection()
|
81 |
-
|
82 |
# THEN: Import your modules
|
83 |
from rag_engine import process_query, load_model, cached_load_data_files
|
84 |
from utils import setup_all_auth
|
|
|
36 |
st.session_state.last_query = ""
|
37 |
st.session_state.last_answer = None
|
38 |
|
39 |
+
# Add a flag to track if we need to check for navigation
|
40 |
+
if 'check_navigation' not in st.session_state:
|
41 |
+
st.session_state.check_navigation = True
|
|
|
|
|
42 |
|
43 |
+
# Check if we need to reset state on page load
|
44 |
+
if st.session_state.check_navigation:
|
45 |
+
# Reset key query-related state variables
|
46 |
+
st.session_state.last_query = ""
|
47 |
+
st.session_state.last_answer = None
|
48 |
+
st.session_state.submit_clicked = False
|
49 |
+
# If you have any other state to reset, do it here
|
50 |
+
|
51 |
+
# Mark that we've checked navigation for this page load
|
52 |
+
st.session_state.check_navigation = False
|
53 |
+
|
54 |
+
# Add JavaScript to reset the flag when navigating away
|
55 |
components.html(
|
56 |
+
"""
|
57 |
<script>
|
58 |
+
// Set up beforeunload event to prepare for next page load
|
59 |
+
window.addEventListener('beforeunload', function() {
|
60 |
+
// This will be executed when the user navigates away
|
61 |
+
// We'll use sessionStorage which persists across page loads
|
62 |
+
sessionStorage.setItem('resetOnReturn', 'true');
|
63 |
+
});
|
64 |
+
|
65 |
+
// Check if we need to reload on return
|
66 |
+
if (sessionStorage.getItem('resetOnReturn') === 'true') {
|
67 |
+
// Clear the flag
|
68 |
+
sessionStorage.removeItem('resetOnReturn');
|
69 |
+
// Force page reload to reset state
|
70 |
+
window.location.reload();
|
71 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
</script>
|
73 |
""",
|
74 |
height=0
|
75 |
)
|
76 |
|
|
|
|
|
|
|
77 |
# THEN: Import your modules
|
78 |
from rag_engine import process_query, load_model, cached_load_data_files
|
79 |
from utils import setup_all_auth
|