will this circuit work as ups for my 5v device?

the circuit is shown in the photo

If i need to make changes in schematic write in comment

Picture of will this circuit work as ups for my 5v device?
Yes, except you only need one relay with a changeover contact, and your C would be better on the supply side of the regulator, not the load, since the maximum voltage it can see on the load side is 5V, whereas on the supply side, it will see 9V, and support the 5 V supply without glitching it.

Of course, you need to get your relay to switch faster than the cap can droop from 9 to 6.5 Volts (when the regulator drops out), unless you use an LDO regulator and you can be 9V to ~5.5 V.

Steve