Hey there,
I’m writing a motion detection / object recognition demo on top of Streamlit and OpenCV. The demo is completely local, so I might as well use a widget toolkit like Tkinter or PyQt, but using Streamlit seems simpler. I can emulate streaming video on the main page of the app with something like this:
# main.py
with st.empty():
while True:
grabbed, frame = stream.read()
if grabbed:
st.image(frame, channels="BGR")
But what I actually want to do is to have the main page fetch and process the frames, then have them render on a subpage, like this:
# main.py
view = st.Page("view.py")
app = st.navigation([view])
app.run()
while True:
grabbed, frame = stream.read()
if grabbed:
process(frame)
# view.py
with st.empty():
st.image(frame, channels="BGR")
I can pass the frame between the pages using a session variable, but the second page doesn’t update while the loop in the first page is running, even if enclose the code in a function decorated with @st.fragment
. Any ideas on how to do this, other than to move the rendering code back into the loop?
Edit: added st.navigation to show relation between pages.