You cannot use cv2 widgets, if streamlit runs on a hosted service.
This does not work because there is a fundamental misunderstanding about how Streamlit works.
Streamlit consists of a frontend and backend part.
Any interaction with streamlit must be done via the browser or browser APIs.
Anything trying to bypass this, may work on your local computer, but will fail as soon as streamlit is hosted, i.e. streamlit no longer runs on the same computer as the browser.
What happens when you try to open cv2 (or other) gui widgets?
They will be opened on the computer on which the python application is running.
But there is neither an UI nor a graphics driver on streamlit cloud and even if there was, it would be the wrong computer.
You have to rethink your whole approach, it will not work this way.