Self-consistent Hartree-Fock calculation of exchange effects in a weakly inhomogeneous electron gas