Probably you can try to make wireguard private tunnel (or other tunnel method) between your flask server and raspi. It should be more stable instead of tor 😅
Discussion
I have done that on nodes in the past. I have a semi working wireguard setup script that sets up both the client and the server. Might try to tweak that and the documentation a bit to make it work with this.
Oh nice, it will be easier for you if you have already some setup
Just in case you want to try and play around with different tunnel tools or methods, you can probably look at this