The galactic habitable zone of the Milky Way and M31 from chemical evolution models with gas radial flows