prasadnu commited on
Commit
88640c9
·
1 Parent(s): 1bea154

ubi integration

Browse files
Files changed (1) hide show
  1. pages/Semantic_Search.py +20 -0
pages/Semantic_Search.py CHANGED
@@ -6,6 +6,7 @@ import os
6
  import sys
7
  import boto3
8
  import requests
 
9
  from requests_aws4auth import AWS4Auth
10
  sys.path.insert(1, "/".join(os.path.realpath(__file__).split("/")[0:-2])+"/semantic_search")
11
  sys.path.insert(1, "/".join(os.path.realpath(__file__).split("/")[0:-2])+"/RAG")
@@ -38,6 +39,7 @@ from streamlit.components.v1 import html
38
  import llm_eval
39
  import all_search_execute
40
  import warnings
 
41
 
42
  warnings.filterwarnings("ignore", category=DeprecationWarning)
43
  st.set_page_config(
@@ -864,12 +866,30 @@ def render_answer(answer,index):
864
  if(sparse_[key]>=1.0):
865
  filtered_sparse[key] = round(sparse_[key], 2)
866
  st.write(filtered_sparse)
 
 
 
867
  with st.expander("Document Metadata:",expanded = False):
868
  st.write(":green[default:]")
869
  st.json({"category:":ans['category'],"price":str(ans['price']),"gender_affinity":ans['gender_affinity'],"style":ans['style']},expanded = True)
870
  if("rekog" in ans):
871
  st.write(":green[enriched:]")
872
  st.json(ans['rekog'],expanded = True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
873
  with inner_col_1:
874
 
875
  if(st.session_state.input_evaluate == "enabled"):
 
6
  import sys
7
  import boto3
8
  import requests
9
+ from datetime import datetime, timedelta
10
  from requests_aws4auth import AWS4Auth
11
  sys.path.insert(1, "/".join(os.path.realpath(__file__).split("/")[0:-2])+"/semantic_search")
12
  sys.path.insert(1, "/".join(os.path.realpath(__file__).split("/")[0:-2])+"/RAG")
 
39
  import llm_eval
40
  import all_search_execute
41
  import warnings
42
+ import utilities.ubi_lambda as ubi
43
 
44
  warnings.filterwarnings("ignore", category=DeprecationWarning)
45
  st.set_page_config(
 
866
  if(sparse_[key]>=1.0):
867
  filtered_sparse[key] = round(sparse_[key], 2)
868
  st.write(filtered_sparse)
869
+ item_id = ans['id'] # use a real ID if available
870
+ expander_key = f"expander_{item_id}"
871
+ opened_key = f"{item_id}_opened"
872
  with st.expander("Document Metadata:",expanded = False):
873
  st.write(":green[default:]")
874
  st.json({"category:":ans['category'],"price":str(ans['price']),"gender_affinity":ans['gender_affinity'],"style":ans['style']},expanded = True)
875
  if("rekog" in ans):
876
  st.write(":green[enriched:]")
877
  st.json(ans['rekog'],expanded = True)
878
+ # Log event only on first open
879
+ if not st.session_state.get(opened_key):
880
+ st.session_state[opened_key] = True
881
+
882
+ # ✅ Build event
883
+ event_payload = {
884
+ "action_name": "expander_open",
885
+ "query_id": st.session_state.get("query_id"),
886
+ "session_id": st.session_state.get("session_id"),
887
+ "item_id": item_id,
888
+ "timestamp": datetime.utcnow().isoformat() + "Z",
889
+ "message_type": "INFO",
890
+ "message": f"Expander opened for item {item_id}"
891
+ }
892
+ status = ubi.send_to_lambda("ubi_events", query_payload)
893
  with inner_col_1:
894
 
895
  if(st.session_state.input_evaluate == "enabled"):