GauriSP10 / streamlit_login_auth_ui

It lets you connect your streamlit application to a pre-built and secure Login/ Sign-Up page.
MIT License
213 stars 65 forks source link

Update st.cache to st.cache_data ro cache_resource #17

Open johnnyb1509 opened 1 year ago

johnnyb1509 commented 1 year ago

Hi maintainer,

As st.cache depreciated on streamlit, please update to other method

tushar-31093 commented 1 year ago

I kept wondering if the code had some issue. Apparently, this library needs an update.

karmataco commented 1 year ago

Is there a work around? I have an error in my home page displaying that I can't get rid of.

johnnyb1509 commented 1 year ago

I think we need to fork the repo then fix it. There r no respondence from author

karmataco commented 1 year ago

I think we need to fork the repo then fix it. There r no respondence from author

I can't even find where the problem is at. I can't find a reference in the code

tushar-31093 commented 1 year ago

I think we need to fork the repo then fix it. There r no respondence from author

I can't even find where the problem is at. I can't find a reference in the code

There is no direct use in the code but the dependencies it builds. The dependencies it installs, somewhere it has this cache method that is outdated and it causes an issue during runtime.

If it were there directly in the code, we would have fixed it already and used it as is.

Maybe update your streamlit versions etc in the base environment and then use this library once. You'd see the issue.

I'll try to share some reproducible code here for what gave the error.

Btw. I did make it vanish by force removing the warning or something I believe. It's working for me.

View the page.

https://alphaai.streamlit.app/

tushar-31093 commented 1 year ago

I think we need to fork the repo then fix it. There r no respondence from author

Possible for you to share screenshots etc for where the issue came in?

karmataco commented 1 year ago

I hid the alert div. Is that how you managed to hide it? Also, I found the culprit and there's a pull request that hasn't been accepted :(. It's literally one line https://github.com/ktosiek/streamlit-cookies-manager/pull/3

Klein-Baru commented 1 year ago

Solution to the st.cache deprecation problem.

I was able to find a way through:

  1. The warning appears on the Firefox browser and does not appear on the Chrome and Brave browsers. (from tests I conducted with streamlit v1.23.1) You can consider switching browsers😂😂.
  2. Add some arguments to the streamlit run <python file> command. Thus to suppress the warnings, use streamlit run <python file> --client.showErrorDetails=false

solutions above are for local host only. Online deployment has not been tested.

RyanBin0126 commented 1 year ago

Discovered the usage of st.cache in the import statement from streamlit_cookies_manager import EncryptedCookieManager. I refactored the code by replacing st.cache with st.cache_data. After restarting PyCharm and reloading the Streamlit app, the warning was resolved.

Klein-Baru commented 1 year ago

@RyanBin0126 Awesome!!. I understand your solution theoretically, I will try it out practically to see it in action.

On Thu, Jun 22, 2023, 3:22 PM RyanBin @.***> wrote:

I found st.cache in "from streamlit_cookies_manager import EncryptedCookieManager". Though I changed st.cache to st.cache_data, i still received a warning. I am keeping looking the other st.cache.

— Reply to this email directly, view it on GitHub https://github.com/GauriSP10/streamlit_login_auth_ui/issues/17#issuecomment-1602542845, or unsubscribe https://github.com/notifications/unsubscribe-auth/A7EDH77DJZ3Z6HJOGN4EQ3LXMQ2GXANCNFSM6AAAAAAXWUA6RQ . You are receiving this because you commented.Message ID: @.***>

Klein-Baru commented 1 year ago

@RyanBin0126 Awesome!!. I understand your solution theoretically, I will try it out practically to see it in action. On Thu, Jun 22, 2023, 3:22 PM RyanBin @.> wrote: I found st.cache in "from streamlit_cookies_manager import EncryptedCookieManager". Though I changed st.cache to st.cache_data, i still received a warning. I am keeping looking the other st.cache. — Reply to this email directly, view it on GitHub <#17 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/A7EDH77DJZ3Z6HJOGN4EQ3LXMQ2GXANCNFSM6AAAAAAXWUA6RQ . You are receiving this because you commented.Message ID: @.>

@RyanBin0126 How do you refactor the st.cache to st.cache_data in Pycharm? I cant find the streamlit-cookies-manager module where st.cache is, presumably, initially declared.

RyanBin0126 commented 1 year ago

@RyanBin0126 Awesome!!. I understand your solution theoretically, I will try it out practically to see it in action. On Thu, Jun 22, 2023, 3:22 PM RyanBin @._> wrote: I found st.cache in "from streamlit_cookies_manager import EncryptedCookieManager". Though I changed st.cache to _st.cachedata, i still received a warning. I am keeping looking the other st.cache. — Reply to this email directly, view it on GitHub <#17 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/A7EDH77DJZ3Z6HJOGN4EQ3LXMQ2GXANCNFSM6AAAAAAXWUA6RQ . You are receiving this because you commented.Message ID: _@_._>

@RyanBin0126 How do you refactor the st.cache to st.cache_data in Pycharm? I cant find the streamlit-cookies-manager module where st.cache is, presumably, initially declared.

@Klein-Baru There are two methods.

The first method is more convenient for those who are using PyCharm. At the place where you initially imported "from streamlit_login_auth_ui.widgets import login", hold the Ctrl key and click on "login" with the mouse. You will be taken to "widgets.py". At the top of the .py file, you will see "from streamlit_cookies_manager import EncryptedCookieManager". Next, jump into the py file "encrypted_cookie_manager" where "EncryptedCookieManager" is located. Line 14, above the method "key_from_parameters", you will find "@st.cache". You can modify it there.

The second method is to directly open the file Miniconda3\envs"your envs"\Lib\site-packages\streamlit_cookies_manager\encrypted_cookie_manager.py in the system and make the modification.

Good luck!

Klein-Baru commented 1 year ago

@RyanBin0126 Awesome!!. I understand your solution theoretically, I will try it out practically to see it in action. On Thu, Jun 22, 2023, 3:22 PM RyanBin @._> wrote: I found st.cache in "from streamlit_cookies_manager import EncryptedCookieManager". Though I changed st.cache to _st.cachedata, i still received a warning. I am keeping looking the other st.cache. — Reply to this email directly, view it on GitHub <#17 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/A7EDH77DJZ3Z6HJOGN4EQ3LXMQ2GXANCNFSM6AAAAAAXWUA6RQ . You are receiving this because you commented.Message ID: _@_._>

@RyanBin0126 How do you refactor the st.cache to st.cache_data in Pycharm? I cant find the streamlit-cookies-manager module where st.cache is, presumably, initially declared.

@Klein-Baru There are two methods.

The first method is more convenient for those who are using PyCharm. At the place where you initially imported "from streamlit_login_auth_ui.widgets import login", hold the Ctrl key and click on "login" with the mouse. You will be taken to "widgets.py". At the top of the .py file, you will see "from streamlit_cookies_manager import EncryptedCookieManager". Next, jump into the py file "encrypted_cookie_manager" where "EncryptedCookieManager" is located. Line 14, above the method "key_from_parameters", you will find "@st.cache". You can modify it there.

The second method is to directly open the file Miniconda3\envs"your envs"\Lib\site-packages\streamlit_cookies_manager\encrypted_cookie_manager.py in the system and make the modification.

Good luck!

@RyanBin0126

Tried method 1 on Pycharm, the warning disappeared!! Thanks for sharing.

woensug-choi commented 1 year ago

tried streamlit run <python file> --client.showErrorDetails=false on deployment and works ok for now..

banstala commented 1 year ago

The --client.showErrorDetails=false option does work-- on the browser (the web-page for login does not show up the warning), but in test environment the warning is still shown on the terminal where the streamlit app is being run.

On the other hand, finding the encrypted_cookie_manager.py file and replacing @st.cache with @st.cache_resource solves the issue on a deeper level-- the warning vanishes from the login page on the browser, as well as on the terminal where the app is being run.

Cheers for both interim solutions, nonetheless !

Will be looking forward to the bug-fix in a future release of streamlit-login-auth-ui.

MaxSeck commented 1 year ago

So I found the encrypted_cookie_manager.py and @st.cache in line 14. When trying to change to @st.cache_data I can't save it and get this error message:

Failed to save 'encrypted_cookie_manager.py': Unable to write file 'vscode-remote://wsl+ubuntu/usr/local/lib/python3.10/dist-packages/streamlit_cookies_manager/encrypted_cookie_manager.py' (NoPermissions (FileSystemError): Error: EACCES: permission denied, open '/usr/local/lib/python3.10/dist-packages/streamlit_cookies_manager/encrypted_cookie_manager.py')

Already tried to change the permission but I still can't save it.

RyanBin0126 commented 1 year ago

So I found the encrypted_cookie_manager.py and @st.cache in line 14. When trying to change to @st.cache_data I can't save it and get this error message:

Failed to save 'encrypted_cookie_manager.py': Unable to write file 'vscode-remote://wsl+ubuntu/usr/local/lib/python3.10/dist-packages/streamlit_cookies_manager/encrypted_cookie_manager.py' (NoPermissions (FileSystemError): Error: EACCES: permission denied, open '/usr/local/lib/python3.10/dist-packages/streamlit_cookies_manager/encrypted_cookie_manager.py')

Already tried to change the permission but I still can't save it.

Try modifying it in a local file instead of the pycharm editor

olsonperrensen commented 6 months ago

Someone wants to make a PR to solve this in main ?