Weighing the Milky Way and Andromeda with Artificial Intelligence