-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Add ability to read and write from LocalStorage #9950
Conversation
🪼 branch checks and previews
Install Gradio from this PR pip install https://gradio-pypi-previews.s3.amazonaws.com/ec2e569baa8a9b69674ad542c99a1ddface86286/gradio-5.5.0-py3-none-any.whl Install Gradio Python Client from this PR pip install "gradio-client @ git+https://github.com/gradio-app/gradio@ec2e569baa8a9b69674ad542c99a1ddface86286#subdirectory=client/python" Install Gradio JS Client from this PR npm install https://gradio-npm-previews.s3.amazonaws.com/ec2e569baa8a9b69674ad542c99a1ddface86286/gradio-client-1.7.1.tgz Use Lite from this PR <script type="module" src="https://gradio-lite-previews.s3.amazonaws.com/ec2e569baa8a9b69674ad542c99a1ddface86286/dist/lite.js""></script> |
🦄 change detectedThis Pull Request includes changes to the following packages.
With the following changelog entry.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool feature 🔥
Should be ready for review now, thanks @aliabid94 for helping me sort out a few Svelte things! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thanks for fixing the issues!
@@ -30,6 +30,7 @@ | |||
stylesheets?: string[]; | |||
path: string; | |||
app_id?: string; | |||
browser_state_secret?: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this still used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope I’ll get rid of it
js/spa/src/Index.svelte
Outdated
@@ -29,6 +29,7 @@ | |||
stylesheets?: string[]; | |||
path: string; | |||
app_id?: string; | |||
browser_state_secret?: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and this one?
self.secret = secret or "".join( | ||
secrets.choice(string.ascii_letters + string.digits) for _ in range(16) | ||
) | ||
self.storage_key = storage_key or "".join( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we've never used this secrets.choice approach to generate keys - we usually use uuid. Not a big deal tho
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Secrets is better as it doesn’t rely on timers etc which are guessable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM good stuff!
Thanks @aliabid94! |
will it be in the next release version? |
@ROBERT-MCDOWELL yes which we are planning for today / Monday |
ok good to know as I had impletemented it with my own solution a week ago..... |
I've added a component
gr.BrowserState()
, which acts similarly togr.State()
but any value written to it is saved to the browser's local storage, so it is preserved across page loads. The value is encrypted with a key, which means that one Gradio app will not be able to read the local state value of another Gradio app.Test demo:
demo/browserstate/run.py
Closes: #3106