Fix to use session_state as a session_specific cache
Browse files
app.py
CHANGED
@@ -20,7 +20,6 @@ from streamlit_webrtc import (
|
|
20 |
WebRtcStreamerContext,
|
21 |
webrtc_streamer,
|
22 |
)
|
23 |
-
from streamlit_webrtc.session_info import get_session_id
|
24 |
|
25 |
HERE = Path(__file__).parent
|
26 |
|
@@ -294,13 +293,13 @@ def app_object_detection():
|
|
294 |
name: str
|
295 |
prob: float
|
296 |
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
|
305 |
confidence_threshold = st.slider(
|
306 |
"Confidence threshold", 0.0, 1.0, DEFAULT_CONFIDENCE_THRESHOLD, 0.05
|
|
|
20 |
WebRtcStreamerContext,
|
21 |
webrtc_streamer,
|
22 |
)
|
|
|
23 |
|
24 |
HERE = Path(__file__).parent
|
25 |
|
|
|
293 |
name: str
|
294 |
prob: float
|
295 |
|
296 |
+
# Session-specific caching
|
297 |
+
cache_key = "object_detection_dnn"
|
298 |
+
if cache_key in st.session_state:
|
299 |
+
net = st.session_state[cache_key]
|
300 |
+
else:
|
301 |
+
net = cv2.dnn.readNetFromCaffe(str(PROTOTXT_LOCAL_PATH), str(MODEL_LOCAL_PATH))
|
302 |
+
st.session_state[cache_key] = net
|
303 |
|
304 |
confidence_threshold = st.slider(
|
305 |
"Confidence threshold", 0.0, 1.0, DEFAULT_CONFIDENCE_THRESHOLD, 0.05
|