Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need Help with Streamlit: Updating/Displaying Counter Value from VideoTransformerBase #1360

Open
Prana-S opened this issue Aug 23, 2023 · 1 comment

Comments

@Prana-S
Copy link

Prana-S commented Aug 23, 2023

Issue Description

I'm working on a Streamlit app that involves real-time video processing using the VideoTransformerBase class. The app is designed to track hand movements and count repetitions. I've successfully implemented the counting logic within the transform method of the VideoTransformerBase class, and I'm trying to display the updated counter value on the Streamlit app interface.

Problem

The counter value (self.right_counter) is correctly updating within the transform method, but I'm having trouble displaying this updated value on the Streamlit interface. I've tried using various Streamlit display functions like st.text, st.write, and even direct HTML rendering using st.markdown, but none of them seem to work within the transform method.

What I've Tried

  1. Using st.text, st.write, and st.markdown to display the counter value.
  2. Placing the Streamlit display code both inside and outside the transform method.
  3. Using st.session_state to store the counter value and attempting to display it.

Code Sample

import streamlit as st
from streamlit_webrtc import VideoTransformerBase, webrtc_streamer, WebRtcMode, VideoHTMLAttributes

class PoseEstimationTransformer(VideoTransformerBase):
    def __init__(self):
        self.right_counter = 0

    def transform(self, frame):
        # Your pose estimation logic here
        # ...

        # Update right counter
        if right_condition:
            self.right_counter += 1

        return frame

def main():
    transformer = PoseEstimationTransformer()
    st.title("Workout Buddy")

    # Display the right curl counter value
    st.text(f"Right Curl Counter: {transformer.right_counter}")

webrtc_ctx = webrtc_streamer(
    key="object-detection",
    mode=WebRtcMode.SENDRECV,
    video_processor_factory=PoseEstimationTransformer,
    media_stream_constraints={"video": True, "audio": False},
    video_html_attrs=VideoHTMLAttributes(
        autoPlay=True, controls=False, style={"width": "100%"},
    ),
)

if __name__ == "__main__":
    main()

Additional Notes:

I suspect that there might be some limitations when using Streamlit display functions within the transform method of the VideoTransformerBase class. I'm looking for guidance on how to properly display the updated counter value on the Streamlit app interface as the video is being processed.

Any help or suggestions would be greatly appreciated. Thank you!

@hengamirah
Copy link

Hi is this issue solved? I am facing the same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants