sradc commited on
Commit
7969559
1 Parent(s): 9357ade

update app.py to use st.cache_resource (much faster/more responsive)

Browse files
Files changed (1) hide show
  1. video_semantic_search/app.py +7 -4
video_semantic_search/app.py CHANGED
@@ -9,6 +9,7 @@ import pandas as pd
9
  import streamlit as st
10
 
11
  from pipeline import clip_wrapper
 
12
 
13
  NUM_FRAMES_TO_RETURN = 21
14
 
@@ -37,8 +38,9 @@ class SemanticSearcher:
37
  ]
38
 
39
 
40
- DATASET_PATH: Final[str] = os.environ.get("DATASET_PATH", "data/dataset.parquet")
41
- SEARCHER: Final[SemanticSearcher] = SemanticSearcher(pd.read_parquet(DATASET_PATH))
 
42
 
43
 
44
  @dataclass
@@ -93,7 +95,7 @@ def display_search_results(results: list[SearchResult]) -> None:
93
  st.markdown(
94
  f"""
95
  <a href="{get_video_url(result.video_id, result.timestamp)}">
96
- <img src="data:image/jpeg;base64,{result.base64_image}" alt="frame {result.frame_idx} timestamp {int(result.timestamp)}" width="100%">
97
  </a>
98
  """,
99
  unsafe_allow_html=True,
@@ -110,9 +112,10 @@ def main():
110
  st.markdown("_App by Ben Tenmann and Sidney Radcliffe_")
111
  st.text_input("What are you looking for?", key="query")
112
  query = st.session_state["query"]
 
113
  if query:
114
  st.text("Click image to open video")
115
- display_search_results(SEARCHER.search(query))
116
 
117
 
118
  if __name__ == "__main__":
 
9
  import streamlit as st
10
 
11
  from pipeline import clip_wrapper
12
+ from pipeline.process_videos import DATAFRAME_PATH
13
 
14
  NUM_FRAMES_TO_RETURN = 21
15
 
 
38
  ]
39
 
40
 
41
+ @st.cache_resource
42
+ def get_semantic_searcher():
43
+ return SemanticSearcher(pd.read_parquet(DATAFRAME_PATH))
44
 
45
 
46
  @dataclass
 
95
  st.markdown(
96
  f"""
97
  <a href="{get_video_url(result.video_id, result.timestamp)}">
98
+ <img src="data:image/jpeg;base64,{result.base64_image.decode()}" alt="frame {result.frame_idx} timestamp {int(result.timestamp)}" width="100%">
99
  </a>
100
  """,
101
  unsafe_allow_html=True,
 
112
  st.markdown("_App by Ben Tenmann and Sidney Radcliffe_")
113
  st.text_input("What are you looking for?", key="query")
114
  query = st.session_state["query"]
115
+ searcher = get_semantic_searcher()
116
  if query:
117
  st.text("Click image to open video")
118
+ display_search_results(searcher.search(query))
119
 
120
 
121
  if __name__ == "__main__":