Update app.py
Browse files
app.py
CHANGED
@@ -23,6 +23,7 @@ def initialize_state():
|
|
23 |
st.session_state.caption_queue = queue.Queue(maxsize=10)
|
24 |
st.session_state.processor = None
|
25 |
st.session_state.thread = None
|
|
|
26 |
st.session_state.initialized = True
|
27 |
|
28 |
@st.cache_resource
|
@@ -121,7 +122,7 @@ def main():
|
|
121 |
# Video source selection
|
122 |
source_type = st.selectbox(
|
123 |
"Select Video Source",
|
124 |
-
["
|
125 |
)
|
126 |
|
127 |
source_path = None
|
@@ -134,15 +135,19 @@ def main():
|
|
134 |
elif source_type == "RTSP Stream":
|
135 |
source_path = st.text_input("Enter RTSP URL", placeholder="rtsp://your-camera-url")
|
136 |
|
137 |
-
start_stop = st.button(
|
|
|
|
|
138 |
video_placeholder = st.empty()
|
139 |
|
140 |
if start_stop:
|
141 |
-
if st.session_state.
|
142 |
# Start surveillance
|
143 |
if st.session_state.processor is None:
|
144 |
st.session_state.processor = load_processor()
|
145 |
st.session_state.stop_event.clear()
|
|
|
|
|
146 |
st.session_state.thread = threading.Thread(
|
147 |
target=process_video,
|
148 |
args=(
|
@@ -156,12 +161,14 @@ def main():
|
|
156 |
daemon=True
|
157 |
)
|
158 |
st.session_state.thread.start()
|
|
|
159 |
else:
|
160 |
# Stop surveillance
|
161 |
st.session_state.stop_event.set()
|
162 |
if st.session_state.thread:
|
163 |
st.session_state.thread.join(timeout=1.0)
|
164 |
st.session_state.frame = None
|
|
|
165 |
video_placeholder.empty()
|
166 |
|
167 |
# Caption column
|
@@ -182,7 +189,7 @@ def main():
|
|
182 |
answer_placeholder.markdown(f"**Answer:** {answer}")
|
183 |
|
184 |
# Update loop
|
185 |
-
if
|
186 |
placeholder = st.empty()
|
187 |
while True:
|
188 |
try:
|
|
|
23 |
st.session_state.caption_queue = queue.Queue(maxsize=10)
|
24 |
st.session_state.processor = None
|
25 |
st.session_state.thread = None
|
26 |
+
st.session_state.is_streaming = False
|
27 |
st.session_state.initialized = True
|
28 |
|
29 |
@st.cache_resource
|
|
|
122 |
# Video source selection
|
123 |
source_type = st.selectbox(
|
124 |
"Select Video Source",
|
125 |
+
["Video File"]
|
126 |
)
|
127 |
|
128 |
source_path = None
|
|
|
135 |
elif source_type == "RTSP Stream":
|
136 |
source_path = st.text_input("Enter RTSP URL", placeholder="rtsp://your-camera-url")
|
137 |
|
138 |
+
start_stop = st.button(
|
139 |
+
"Start Surveillance" if not st.session_state.is_streaming else "Stop Surveillance"
|
140 |
+
)
|
141 |
video_placeholder = st.empty()
|
142 |
|
143 |
if start_stop:
|
144 |
+
if not st.session_state.is_streaming:
|
145 |
# Start surveillance
|
146 |
if st.session_state.processor is None:
|
147 |
st.session_state.processor = load_processor()
|
148 |
st.session_state.stop_event.clear()
|
149 |
+
st.session_state.frame_queue = queue.Queue(maxsize=1)
|
150 |
+
st.session_state.caption_queue = queue.Queue(maxsize=10)
|
151 |
st.session_state.thread = threading.Thread(
|
152 |
target=process_video,
|
153 |
args=(
|
|
|
161 |
daemon=True
|
162 |
)
|
163 |
st.session_state.thread.start()
|
164 |
+
st.session_state.is_streaming = True
|
165 |
else:
|
166 |
# Stop surveillance
|
167 |
st.session_state.stop_event.set()
|
168 |
if st.session_state.thread:
|
169 |
st.session_state.thread.join(timeout=1.0)
|
170 |
st.session_state.frame = None
|
171 |
+
st.session_state.is_streaming = False
|
172 |
video_placeholder.empty()
|
173 |
|
174 |
# Caption column
|
|
|
189 |
answer_placeholder.markdown(f"**Answer:** {answer}")
|
190 |
|
191 |
# Update loop
|
192 |
+
if st.session_state.is_streaming:
|
193 |
placeholder = st.empty()
|
194 |
while True:
|
195 |
try:
|