Spaces:
Running
Running
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +33 -4
src/streamlit_app.py
CHANGED
@@ -821,12 +821,18 @@ def get_random_unvoted_comment(user_id, topic_id):
|
|
821 |
# Check if cluster label has changed AND the set of users in the new cluster is different
|
822 |
# This indicates the user has moved to a different group of commenters
|
823 |
if current_label is not None and previous_label is not None and current_label != previous_label:
|
824 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
825 |
# Set a flag in session state to display the message later in the main rendering logic
|
826 |
-
print("st.session_state._show_new_area_message = True")
|
827 |
-
print("st.session_state._show_new_area_message = True")
|
828 |
st.session_state._show_new_area_message = True
|
829 |
-
|
|
|
|
|
830 |
st.session_state._new_area_comments = new_area_comments
|
831 |
# print(f"DEBUG: Cluster changed for user {user_id} in topic {topic_id}: {previous_label} -> {current_label}")
|
832 |
# print(f"DEBUG: Previous users count: {len(previous_users_set)}, Current users count: {len(current_users_set)}")
|
@@ -970,6 +976,7 @@ def create_topic_page():
|
|
970 |
st.session_state.page = 'home'
|
971 |
st.rerun()
|
972 |
|
|
|
973 |
def view_topic_page():
|
974 |
topic_id = st.session_state.get('current_topic_id')
|
975 |
user_email = st.session_state.get('user_email', '')
|
@@ -1300,6 +1307,28 @@ def view_topic_page():
|
|
1300 |
st.session_state.page = 'home'
|
1301 |
st.rerun()
|
1302 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1303 |
# Initialize session state for navigation and data
|
1304 |
if 'page' not in st.session_state:
|
1305 |
st.session_state.page = 'home'
|
|
|
821 |
# Check if cluster label has changed AND the set of users in the new cluster is different
|
822 |
# This indicates the user has moved to a different group of commenters
|
823 |
if current_label is not None and previous_label is not None and current_label != previous_label:
|
824 |
+
# Calculate overlap (Jaccard Index)
|
825 |
+
intersection_size = len(current_users_set.intersection(previous_users_set))
|
826 |
+
union_size = len(current_users_set.union(previous_users_set))
|
827 |
+
|
828 |
+
# Check if overlap (Jaccard) is over 70%
|
829 |
+
# Handle case where union_size is 0 (both sets empty)
|
830 |
+
if union_size > 0 and (intersection_size / union_size) > 0.7:
|
831 |
# Set a flag in session state to display the message later in the main rendering logic
|
|
|
|
|
832 |
st.session_state._show_new_area_message = True
|
833 |
+
# Fetch comments from the NEW area (current_users_set)
|
834 |
+
# Note: get_top_k_consensus_comments_for_users expects a list, not a set
|
835 |
+
new_area_comments = get_top_k_consensus_comments_for_users(list(current_users_set), topic_id, k=5)
|
836 |
st.session_state._new_area_comments = new_area_comments
|
837 |
# print(f"DEBUG: Cluster changed for user {user_id} in topic {topic_id}: {previous_label} -> {current_label}")
|
838 |
# print(f"DEBUG: Previous users count: {len(previous_users_set)}, Current users count: {len(current_users_set)}")
|
|
|
976 |
st.session_state.page = 'home'
|
977 |
st.rerun()
|
978 |
|
979 |
+
|
980 |
def view_topic_page():
|
981 |
topic_id = st.session_state.get('current_topic_id')
|
982 |
user_email = st.session_state.get('user_email', '')
|
|
|
1307 |
st.session_state.page = 'home'
|
1308 |
st.rerun()
|
1309 |
|
1310 |
+
# st.components.v1.html("""
|
1311 |
+
# <script>
|
1312 |
+
# document.addEventListener('DOMContentLoaded', function() {
|
1313 |
+
# // 监听 DOM 变化
|
1314 |
+
# const observer = new MutationObserver(() => scrollToTarget());
|
1315 |
+
# observer.observe(document.body, {
|
1316 |
+
# childList: true,
|
1317 |
+
# subtree: true,
|
1318 |
+
# attributes: true
|
1319 |
+
# });
|
1320 |
+
# });
|
1321 |
+
|
1322 |
+
|
1323 |
+
# // 滚动到目标元素
|
1324 |
+
# function scrollToTarget() {
|
1325 |
+
# const target = document.querySelector("div.stColumn");
|
1326 |
+
# if (target) {
|
1327 |
+
# target.scrollIntoView({ behavior: "smooth", block: "center" });
|
1328 |
+
# }
|
1329 |
+
# }
|
1330 |
+
# </script>""")
|
1331 |
+
|
1332 |
# Initialize session state for navigation and data
|
1333 |
if 'page' not in st.session_state:
|
1334 |
st.session_state.page = 'home'
|