npc0 commited on
Commit
ab3cab2
·
verified ·
1 Parent(s): 71df7c3

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +16 -9
src/streamlit_app.py CHANGED
@@ -590,7 +590,7 @@ def get_random_unvoted_comment(user_id, topic_id):
590
  """, [topic_id, user_id]).fetchone()
591
  if result:
592
  # Check for cluster change and set message flag
593
- current_label, current_users = get_user_cluster_label(user_id, topic_id)
594
  current_users_set = set(current_users)
595
 
596
  previous_label = st.session_state.get('_previous_cluster_label')
@@ -662,7 +662,7 @@ def update_user_progress(user_id, topic_id, comment_id):
662
  def share_wisdom(prompt, allow_skip=False):
663
  st.markdown(prompt)
664
  new_comment_text = st.text_area(f"Your Insight {'that different from others above (Empty to skip)' if allow_skip else ''}", key="new_comment_input")
665
- if st.button("Share Your Wisdom"):
666
  if new_comment_text:
667
  user_email = st.session_state.get('user_email', '')
668
  user_id = find_or_create_user(user_email) # Ensure user exists
@@ -834,7 +834,7 @@ def view_topic_page():
834
  # Include functional information
835
  st.markdown(f"**Shareable Quest Scroll ID:** `{topic_id}`")
836
  # Construct shareable link using current app URL
837
- app_url = st.query_params.get('base', ['https://huggingface.co/spaces/npc0/SteamPolis/'])[0] # Get base URL if available
838
  shareable_link = f"{app_url}?topic={topic_id}" if app_url else f"?topic={topic_id}"
839
  st.markdown(f"**Shareable Scroll Link:** `{shareable_link}`")
840
 
@@ -931,10 +931,10 @@ def view_topic_page():
931
  if current_comment_id: # Only show voting if there's a comment to vote on
932
  # Display comment history and the current comment with the random intro
933
  if show_new_area_message == True:
934
- _, user_ids = get_user_cluster_label(user_id)
935
  new_area_name, desc = name_user_group(user_ids, topic_id)
936
- st.markdown(f"You've collected {len(comment_history.splitlines())} insights so far.")
937
- st.markdown(f"And yet a new place you have arrived: `{new_area_name}`. {desc}")
938
  st.session_state._show_new_area_message = False
939
  st.markdown(f"[Collected new insight, {random_phrase}]:\n* {current_comment_content}")
940
 
@@ -1013,15 +1013,22 @@ def view_topic_page():
1013
  if local_con:
1014
  local_con.close()
1015
 
 
1016
  col1, col2, col3, col4 = st.columns(4)
1017
  user_id = find_or_create_user(user_email) # Ensure user exists
1018
 
1019
  col1.markdown("*Personally I...*")
1020
- if col2.button("Agree"):
 
 
1021
  handle_vote("agree", current_comment_id, topic_id, user_id)
1022
- if col3.button("Neutral"):
 
 
1023
  handle_vote("neutral", current_comment_id, topic_id, user_id)
1024
- if col4.button("Disagree"):
 
 
1025
  handle_vote("disagree", current_comment_id, topic_id, user_id)
1026
 
1027
  else:
 
590
  """, [topic_id, user_id]).fetchone()
591
  if result:
592
  # Check for cluster change and set message flag
593
+ current_label, current_users = get_user_cluster_label(user_id, get_ttl_hash(10))
594
  current_users_set = set(current_users)
595
 
596
  previous_label = st.session_state.get('_previous_cluster_label')
 
662
  def share_wisdom(prompt, allow_skip=False):
663
  st.markdown(prompt)
664
  new_comment_text = st.text_area(f"Your Insight {'that different from others above (Empty to skip)' if allow_skip else ''}", key="new_comment_input")
665
+ if st.button("Share Your Wisdom", key=f"share_wisdom_button_{random.randint(1, 11)}"):
666
  if new_comment_text:
667
  user_email = st.session_state.get('user_email', '')
668
  user_id = find_or_create_user(user_email) # Ensure user exists
 
834
  # Include functional information
835
  st.markdown(f"**Shareable Quest Scroll ID:** `{topic_id}`")
836
  # Construct shareable link using current app URL
837
+ app_url = st.query_params.get('base', ['http://localhost:8501/'])[0] # Get base URL if available
838
  shareable_link = f"{app_url}?topic={topic_id}" if app_url else f"?topic={topic_id}"
839
  st.markdown(f"**Shareable Scroll Link:** `{shareable_link}`")
840
 
 
931
  if current_comment_id: # Only show voting if there's a comment to vote on
932
  # Display comment history and the current comment with the random intro
933
  if show_new_area_message == True:
934
+ _, user_ids = get_user_cluster_label(user_id, get_ttl_hash(10))
935
  new_area_name, desc = name_user_group(user_ids, topic_id)
936
+ st.markdown(f"📚 You've collected **{len(comment_history.splitlines())}** insights this time.")
937
+ st.markdown(f"🗺️ And yet, your journey leads you to a new place: **{new_area_name}**! {desc}")
938
  st.session_state._show_new_area_message = False
939
  st.markdown(f"[Collected new insight, {random_phrase}]:\n* {current_comment_content}")
940
 
 
1013
  if local_con:
1014
  local_con.close()
1015
 
1016
+ st.session_state._voting_in_progress = False
1017
  col1, col2, col3, col4 = st.columns(4)
1018
  user_id = find_or_create_user(user_email) # Ensure user exists
1019
 
1020
  col1.markdown("*Personally I...*")
1021
+ if col2.button("Agree", disabled=st.session_state.get('_voting_in_progress', False)):
1022
+ # Set a flag immediately to disable buttons until next render
1023
+ st.session_state._voting_in_progress = True
1024
  handle_vote("agree", current_comment_id, topic_id, user_id)
1025
+ if col3.button("Neutral", disabled=st.session_state.get('_voting_in_progress', False)):
1026
+ # Set a flag immediately to disable buttons until next render
1027
+ st.session_state._voting_in_progress = True
1028
  handle_vote("neutral", current_comment_id, topic_id, user_id)
1029
+ if col4.button("Disagree", disabled=st.session_state.get('_voting_in_progress', False)):
1030
+ # Set a flag immediately to disable buttons until next render
1031
+ st.session_state._voting_in_progress = True
1032
  handle_vote("disagree", current_comment_id, topic_id, user_id)
1033
 
1034
  else: