Spaces:
Sleeping
Sleeping
dillonlaird
commited on
Commit
•
2c0045a
1
Parent(s):
78b6d28
updated app, removed keys
Browse files- app.py +32 -12
- pages/run_inference.py +0 -33
app.py
CHANGED
@@ -1,24 +1,44 @@
|
|
|
|
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
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
|
24 |
-
st.
|
|
|
|
1 |
+
import os
|
2 |
import streamlit as st
|
3 |
|
4 |
+
from pathlib import Path
|
5 |
+
from landingai.predict import Predictor
|
6 |
+
from landingai.vision_pipeline import NetworkedCamera, FrameSet
|
7 |
+
|
8 |
+
|
9 |
+
VIDEO_CACHE_PATH = Path("cached_data")
|
10 |
+
VIDEO_CACHE_PATH.mkdir(exist_ok=True, parents=True)
|
11 |
+
VIDEO_CACHE_PATH = VIDEO_CACHE_PATH / "latest.mp4"
|
12 |
+
VIDEO_LEN_SEC = 10
|
13 |
+
FPS = 2
|
14 |
+
PLAYLIST_URL = (
|
15 |
+
"https://live.hdontap.com/hls/hosb1/topanga_swellmagnet.stream/playlist.m3u8"
|
16 |
+
)
|
17 |
+
API_KEY = os.environ["API_KEY"]
|
18 |
+
ENDPOINT_ID = os.environ["ENDPOINT_ID"]
|
19 |
+
|
20 |
|
21 |
st.title("Topanga Beach Surfer Counter")
|
22 |
st.write(
|
23 |
"This application will grab the latest 10s clip of surfers from the Topanga Beach surf cam"
|
24 |
"and count the number of surfers there."
|
25 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
|
28 |
+
def get_latest_surfer_count():
|
29 |
+
vid_src = NetworkedCamera(PLAYLIST_URL, fps=FPS)
|
30 |
+
surfer_model = Predictor(ENDPOINT_ID, api_key=API_KEY)
|
31 |
+
|
32 |
+
frs = FrameSet()
|
33 |
+
for i, frame in enumerate(vid_src):
|
34 |
+
if i >= VIDEO_LEN_SEC * FPS:
|
35 |
+
break
|
36 |
+
frs.extend(frame.run_predict(predictor=surfer_model).overlay_predictions())
|
37 |
+
frs.save_video(str(VIDEO_CACHE_PATH), video_fps=FPS, image_src="overlay")
|
38 |
+
surfers = frs.get_class_counts()["surfer"] / (VIDEO_LEN_SEC * FPS)
|
39 |
+
st.video(open(VIDEO_CACHE_PATH, "rb").read())
|
40 |
+
st.write(f"Surfer count: **{surfers}**")
|
41 |
|
42 |
|
43 |
+
st.title("Surfer Counter")
|
44 |
+
button = st.button("Get Topanga Beach Surfer Count", on_click=get_latest_surfer_count)
|
pages/run_inference.py
DELETED
@@ -1,33 +0,0 @@
|
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|