How do I persist component value on reload?

Let’s say I have a global state variable called count=0

Then I use it to create a number component:

num = gr.Number(value=count)

I can keep updating num whenever count is supposed to change but there is a problem when reloading the page. num would contain 0 instead of current value of count.

How do I make num store the latest value of count?
I also want this to be possible in Jupyter notebook when running a cell with %%blocks magic command (I like to open the localhost URL in browser to maximize screen space. It means that I can also reload the page.).