SuhasGholkar commited on
Commit
8398bc0
Β·
verified Β·
1 Parent(s): a4e3743

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -11
app.py CHANGED
@@ -1043,8 +1043,23 @@ def load_schema_registry():
1043
  with open(SCHEMA_FILE, "r") as f:
1044
  return yaml.safe_load(f)
1045
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1046
  def render_feedback_controls(chat_id: int, key_ns: str | None = None):
1047
- # Ensure unique widget namespace to avoid DuplicateWidgetID
1048
  try:
1049
  import streamlit as st
1050
  if key_ns is None:
@@ -1070,16 +1085,15 @@ def render_feedback_controls(chat_id: int, key_ns: str | None = None):
1070
  st.info("Feedback recorded: " + ("πŸ‘ Helpful" if existing == 1 else "πŸ‘Ž Not helpful"))
1071
  return
1072
 
1073
- if btn_up:
1074
- try:
1075
- update_chat_feedback(chat_id, 1)
1076
- st.success("Thanks for the feedback! Recorded as πŸ‘ Helpful.")
1077
  except Exception as e:
1078
  st.error("Could not save feedback."); st.exception(e)
1079
- elif btn_dn:
1080
- try:
1081
- update_chat_feedback(chat_id, 0)
1082
- st.success(_localize_msg("Thanks for the feedback! Recorded as πŸ‘Ž Not helpful.",src_lang))
1083
  except Exception as e:
1084
  st.error(_localize_msg("Could not save feedback.",src_lang)); st.exception(e)
1085
 
@@ -4188,7 +4202,7 @@ def admin_rag_publisher(registry: dict):
4188
  except Exception:
4189
  return str(x)
4190
 
4191
- view = view.map(_ui_safe_cell_local)
4192
  view.insert(0, "Select", False)
4193
  st.caption("Tick up to 50 rows to publish.")
4194
  edited = st.data_editor(
@@ -4643,7 +4657,7 @@ with tab_chat:
4643
 
4644
  # Ensure transcript has latest turn appended (once per turn)
4645
  _out = st.session_state.get('last_chat_out')
4646
- _last_user = st.session_state.get("last_user_text") or st.session_state.get("last_query_text")
4647
  if _out is not None and _last_user:
4648
  _t = st.session_state.setdefault('transcript', [])
4649
  if (not _t) or (_t[-1].get('user') != _last_user):
@@ -5141,3 +5155,20 @@ if auth["role"] == "admin":
5141
  logger.exception("Failed load schema registry : %s", e)
5142
  reg = load_schema_registry(os.path.join(DATA_DIR, SCHEMA_FILE))
5143
  admin_rag_publisher(reg)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1043
  with open(SCHEMA_FILE, "r") as f:
1044
  return yaml.safe_load(f)
1045
 
1046
+ # --- Feedback confirmation persistence helper ---
1047
+ def _feedback_confirmed(chat_id: int) -> bool:
1048
+ try:
1049
+ import streamlit as st
1050
+ return bool(st.session_state.get(f"FB_CONFIRMED_{chat_id}"))
1051
+ except Exception:
1052
+ return False
1053
+
1054
+ def _set_feedback_confirmed(chat_id: int, val: bool = True) -> None:
1055
+ try:
1056
+ import streamlit as st
1057
+ st.session_state[f"FB_CONFIRMED_{chat_id}"] = val
1058
+ except Exception:
1059
+ pass
1060
+
1061
  def render_feedback_controls(chat_id: int, key_ns: str | None = None):
1062
+ # Unique widget namespace to avoid DuplicateWidgetID
1063
  try:
1064
  import streamlit as st
1065
  if key_ns is None:
 
1085
  st.info("Feedback recorded: " + ("πŸ‘ Helpful" if existing == 1 else "πŸ‘Ž Not helpful"))
1086
  return
1087
 
1088
+ _set_feedback_confirmed(chat_id, True)
1089
+ st.toast('πŸ‘ Thanks!')
1090
+ success("Thanks for the feedback! Recorded as πŸ‘ Helpful.")
 
1091
  except Exception as e:
1092
  st.error("Could not save feedback."); st.exception(e)
1093
+
1094
+ _set_feedback_confirmed(chat_id, True)
1095
+ st.toast('πŸ‘Ž Recorded')
1096
+ success(_localize_msg("Thanks for the feedback! Recorded as πŸ‘Ž Not helpful.",src_lang))
1097
  except Exception as e:
1098
  st.error(_localize_msg("Could not save feedback.",src_lang)); st.exception(e)
1099
 
 
4202
  except Exception:
4203
  return str(x)
4204
 
4205
+ view = view.applymap(_ui_safe_cell_local)
4206
  view.insert(0, "Select", False)
4207
  st.caption("Tick up to 50 rows to publish.")
4208
  edited = st.data_editor(
 
4657
 
4658
  # Ensure transcript has latest turn appended (once per turn)
4659
  _out = st.session_state.get('last_chat_out')
4660
+ _last_user = st.session_state.get('last_query_text')
4661
  if _out is not None and _last_user:
4662
  _t = st.session_state.setdefault('transcript', [])
4663
  if (not _t) or (_t[-1].get('user') != _last_user):
 
5155
  logger.exception("Failed load schema registry : %s", e)
5156
  reg = load_schema_registry(os.path.join(DATA_DIR, SCHEMA_FILE))
5157
  admin_rag_publisher(reg)
5158
+
5159
+
5160
+ def _render_rag_publisher_safe():
5161
+ import streamlit as st
5162
+ try:
5163
+ if 'auth' in st.session_state and st.session_state['auth'].get('role') == 'admin':
5164
+ # lazy import or call existing renderer if present
5165
+ if 'render_rag_publisher' in globals():
5166
+ _render_rag_publisher_safe()
5167
+ elif 'rag_publisher' in globals() and hasattr(rag_publisher, 'render'):
5168
+ rag_publisher.render()
5169
+ else:
5170
+ st.info("RAG Publisher module not loaded. Please ensure `_render_rag_publisher_safe()` is defined.")
5171
+ else:
5172
+ st.warning("RAG Publisher is available to admins only.")
5173
+ except Exception as e:
5174
+ st.error(f"RAG Publisher failed: {e}")