The gravitational force loses strength as a function of distance less rapidly than the nuclear force, but at very close ranges, such as those found within a single atom, the nuclear force is much stronger. So if the nucleons were each on opposite sides of a solar system, or even of a room, the force of gravity would be stronger, but in the described case the nuclear force is stronger.