Optical and electronic properties of the layered semiconductors NiPS3 and FePS3