Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,12 +8,12 @@ import pytz
|
|
8 |
|
9 |
# Page config and header
|
10 |
st.set_page_config(
|
11 |
-
page_title="
|
12 |
page_icon="🔥",
|
13 |
layout="wide",
|
14 |
initial_sidebar_state="expanded"
|
15 |
)
|
16 |
-
st.title("
|
17 |
|
18 |
# --- Session State Initialization ---
|
19 |
if "streams" not in st.session_state:
|
@@ -54,7 +54,7 @@ default_names = [
|
|
54 |
# --- Sidebar Settings ---
|
55 |
with st.sidebar:
|
56 |
st.header("Stream Settings")
|
57 |
-
# Custom configuration for stream 1
|
58 |
custom_m3u8 = st.text_input("Custom M3U8 URL for Stream 1 (optional)", value="", key="custom_m3u8")
|
59 |
custom_name = st.text_input("Custom Webcam Name for Stream 1 (optional)", value="", key="custom_name")
|
60 |
|
@@ -76,7 +76,7 @@ with st.sidebar:
|
|
76 |
video_option = st.selectbox("Processing Rate", list(fps_options.keys()), index=3)
|
77 |
st.session_state.target_fps = fps_options[video_option]
|
78 |
|
79 |
-
#
|
80 |
if len(st.session_state.streams) != st.session_state.num_streams:
|
81 |
st.session_state.streams = []
|
82 |
for i in range(st.session_state.num_streams):
|
@@ -150,7 +150,6 @@ def update_stream(i):
|
|
150 |
return
|
151 |
res = model.predict(frame, conf=confidence)
|
152 |
processed_frame = res[0].plot()[:, :, ::-1]
|
153 |
-
# Extract detection results.
|
154 |
tensor_info = "No detections"
|
155 |
max_conf = 0.0
|
156 |
try:
|
@@ -160,7 +159,6 @@ def update_stream(i):
|
|
160 |
tensor_info = f"Detections: {len(boxes)} | Max Confidence: {max_conf:.2f}"
|
161 |
except Exception as ex:
|
162 |
tensor_info = f"Error extracting detections: {ex}"
|
163 |
-
# Only update if new detection's confidence is >= current highest.
|
164 |
if max_conf >= stream_state["highest_match"]:
|
165 |
stream_state["highest_match"] = max_conf
|
166 |
stream_state["detected_frames"].append(processed_frame)
|
@@ -180,12 +178,8 @@ def update_stream(i):
|
|
180 |
)
|
181 |
stats_placeholders[i].text(stream_state["stats_text"])
|
182 |
|
183 |
-
# ---
|
184 |
-
# Using Streamlit's experimental rerun mechanism to update frames.
|
185 |
-
# This loop runs once per script execution; Streamlit will re-run the script as needed.
|
186 |
for i in range(num_streams):
|
187 |
update_stream(i)
|
188 |
-
|
189 |
-
# Trigger a rerun after a short delay for continuous updates
|
190 |
time.sleep(1.0 / target_fps)
|
191 |
st.experimental_rerun()
|
|
|
8 |
|
9 |
# Page config and header
|
10 |
st.set_page_config(
|
11 |
+
page_title="Your Original App",
|
12 |
page_icon="🔥",
|
13 |
layout="wide",
|
14 |
initial_sidebar_state="expanded"
|
15 |
)
|
16 |
+
st.title("Your Original App")
|
17 |
|
18 |
# --- Session State Initialization ---
|
19 |
if "streams" not in st.session_state:
|
|
|
54 |
# --- Sidebar Settings ---
|
55 |
with st.sidebar:
|
56 |
st.header("Stream Settings")
|
57 |
+
# Custom configuration for stream 1 (optional)
|
58 |
custom_m3u8 = st.text_input("Custom M3U8 URL for Stream 1 (optional)", value="", key="custom_m3u8")
|
59 |
custom_name = st.text_input("Custom Webcam Name for Stream 1 (optional)", value="", key="custom_name")
|
60 |
|
|
|
76 |
video_option = st.selectbox("Processing Rate", list(fps_options.keys()), index=3)
|
77 |
st.session_state.target_fps = fps_options[video_option]
|
78 |
|
79 |
+
# Initialize or update stream state
|
80 |
if len(st.session_state.streams) != st.session_state.num_streams:
|
81 |
st.session_state.streams = []
|
82 |
for i in range(st.session_state.num_streams):
|
|
|
150 |
return
|
151 |
res = model.predict(frame, conf=confidence)
|
152 |
processed_frame = res[0].plot()[:, :, ::-1]
|
|
|
153 |
tensor_info = "No detections"
|
154 |
max_conf = 0.0
|
155 |
try:
|
|
|
159 |
tensor_info = f"Detections: {len(boxes)} | Max Confidence: {max_conf:.2f}"
|
160 |
except Exception as ex:
|
161 |
tensor_info = f"Error extracting detections: {ex}"
|
|
|
162 |
if max_conf >= stream_state["highest_match"]:
|
163 |
stream_state["highest_match"] = max_conf
|
164 |
stream_state["detected_frames"].append(processed_frame)
|
|
|
178 |
)
|
179 |
stats_placeholders[i].text(stream_state["stats_text"])
|
180 |
|
181 |
+
# --- Update Streams and Rerun ---
|
|
|
|
|
182 |
for i in range(num_streams):
|
183 |
update_stream(i)
|
|
|
|
|
184 |
time.sleep(1.0 / target_fps)
|
185 |
st.experimental_rerun()
|