sradc commited on
Commit
a2309ed
1 Parent(s): 15402aa

log hash of ip with hash of query so can track number of users and number of queries anonymously

Browse files
Files changed (1) hide show
  1. video_semantic_search/app.py +19 -1
video_semantic_search/app.py CHANGED
@@ -9,7 +9,9 @@ import faiss
9
  import numpy as np
10
  import pandas as pd
11
  import streamlit as st
 
12
  from streamlit.logger import get_logger
 
13
 
14
  from pipeline import clip_wrapper
15
  from pipeline.process_videos import DATAFRAME_PATH
@@ -117,6 +119,20 @@ def display_search_results(results: list[SearchResult]) -> None:
117
  col_num = 0
118
 
119
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
  def main():
121
  st.set_page_config(page_title="video-semantic-search", layout="wide")
122
  st.header("Visual content search over music videos")
@@ -128,7 +144,9 @@ def main():
128
  )
129
  query = st.session_state["query"]
130
  if query:
131
- logger.info(f"Recieved query... {hashlib.md5(query.encode()).hexdigest()}")
 
 
132
  st.text("Click image to open video")
133
  display_search_results(searcher.search(query))
134
  if get_git_hash():
 
9
  import numpy as np
10
  import pandas as pd
11
  import streamlit as st
12
+ from streamlit import runtime
13
  from streamlit.logger import get_logger
14
+ from streamlit.runtime.scriptrunner import get_script_run_ctx
15
 
16
  from pipeline import clip_wrapper
17
  from pipeline.process_videos import DATAFRAME_PATH
 
119
  col_num = 0
120
 
121
 
122
+ def get_remote_ip() -> str:
123
+ """Get remote ip."""
124
+ try:
125
+ ctx = get_script_run_ctx()
126
+ if ctx is None:
127
+ return None
128
+ session_info = runtime.get_instance().get_client(ctx.session_id)
129
+ if session_info is None:
130
+ return None
131
+ except Exception as e:
132
+ return None
133
+ return session_info.request.remote_ip
134
+
135
+
136
  def main():
137
  st.set_page_config(page_title="video-semantic-search", layout="wide")
138
  st.header("Visual content search over music videos")
 
144
  )
145
  query = st.session_state["query"]
146
  if query:
147
+ query_sha256 = hashlib.sha256(query.encode()).hexdigest()[:10]
148
+ ip_sha256 = hashlib.sha256(get_remote_ip().encode()).hexdigest()[:10]
149
+ logger.info(f"sha256(ip)={ip_sha256} sha256(query)={query_sha256}")
150
  st.text("Click image to open video")
151
  display_search_results(searcher.search(query))
152
  if get_git_hash():