whitphx / streamlit-webrtc

Real-time video and audio processing on Streamlit
https://discuss.streamlit.io/t/new-component-streamlit-webrtc-a-new-way-to-deal-with-real-time-media-streams/8669
MIT License
1.36k stars 182 forks source link

Unable to display results in st.write inside recv #411

Closed gauthamk28 closed 2 years ago

gauthamk28 commented 3 years ago

Hi @whitphx thank you for giving this amazing streamlit-webrtc . When I am running the app , I want to display the name of the person detected , when I use print(variable name) , the name of the person is getting printed , whereas when I use st.write(recv) inside recv .

class OpenCVVideoProcessor(VideoProcessorBase):
    def recv(self, frame: av.VideoFrame) -> av.VideoFrame:
    ...
    ...
    st.write(detected_result)

Is there any way to display the result of object detection in html or is there anyway to connect this app with FastAPI , because I need to use this value to do more tasks outside python. I am new so please give any idea which will be helpful for me.

whitphx commented 3 years ago

You cannot use Streamlit methods (st.*) inside recv() because recv() is running in a different thread from the main one.

For your purpose, refer to the object detection demo for example. In this example, the detection result is transferred from recv() to the main script through the Processor instance's attribute and displayed with st.table().