dillonlaird commited on
Commit
78b6d28
1 Parent(s): 5cb14f7

initial commit

Browse files
Files changed (3) hide show
  1. app.py +24 -0
  2. pages/run_inference.py +33 -0
  3. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+
4
+ st.title("Topanga Beach Surfer Counter")
5
+ st.write(
6
+ "This application will grab the latest 10s clip of surfers from the Topanga Beach surf cam"
7
+ "and count the number of surfers there."
8
+ )
9
+ st.write("Please enter your LandingLens API key and Cloud Inference Endpoint ID.")
10
+ api_key = st.text_input(
11
+ "LandingLens API Key", value=st.session_state.get("api_key", "")
12
+ )
13
+ endpoint_id = st.text_input(
14
+ "Cloud Inference Endpoint ID",
15
+ value=st.session_state.get("endpoint_id", ""),
16
+ )
17
+
18
+
19
+ def save(api_key: str, endpoint_id: str):
20
+ st.session_state["api_key"] = api_key
21
+ st.session_state["endpoint_id"] = endpoint_id
22
+
23
+
24
+ st.button("Save", on_click=save(api_key, endpoint_id))
pages/run_inference.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ from pathlib import Path
4
+ from landingai.predict import Predictor
5
+ from landingai.vision_pipeline import NetworkedCamera, FrameSet
6
+
7
+
8
+ VIDEO_CACHE_PATH = Path("cached_data")
9
+ VIDEO_CACHE_PATH.mkdir(exist_ok=True, parents=True)
10
+ VIDEO_CACHE_PATH = VIDEO_CACHE_PATH / "latest.mp4"
11
+ VIDEO_LEN_SEC = 10
12
+ FPS = 2
13
+ PLAYLIST_URL = (
14
+ "https://live.hdontap.com/hls/hosb1/topanga_swellmagnet.stream/playlist.m3u8"
15
+ )
16
+
17
+
18
+ def get_latest_surfer_count():
19
+ vid_src = NetworkedCamera(PLAYLIST_URL, fps=FPS)
20
+ surfer_model = Predictor(st.session_state["endpoint_id"], api_key=st.session_state["api_key"])
21
+
22
+ frs = FrameSet()
23
+ for i, frame in enumerate(vid_src):
24
+ if i >= VIDEO_LEN_SEC * FPS:
25
+ break
26
+ frs.extend(frame.run_predict(predictor=surfer_model).overlay_predictions())
27
+ frs.save_video(str(VIDEO_CACHE_PATH), video_fps=FPS, image_src="overlay")
28
+ surfers = frs.get_class_counts()["surfer"] / (VIDEO_LEN_SEC * FPS)
29
+ st.video(open(VIDEO_CACHE_PATH, "rb").read())
30
+ st.write(f"Surfer count: **{surfers}**")
31
+
32
+ st.title("Surfer Counter")
33
+ button = st.button("Get Topanga Beach Surfer Count", on_click=get_latest_surfer_count)
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ landingai