The contribution of AGNs and star-forming galaxies to the mid-infrared as revealed by their spectral energy distributions