Just add a layer of white/building/birdcage sand on top. This should keep the gnats at bay! Since these types of sand aren't as accessible as potting soil or cocos. Also, gnats only come up when your roots are starting to rot (or when there's active fungi growing rapidly), so you might want to ease down on the watering.
I've never had gnats until I started over-watering my plants and reusing/recyclingwithoutcycling my old soils with the roots still in them. The gnats weren't a real problem though. Keep the soil dry for a couple (3) of days, maybe run your lights at half the strength so your babies won't die, and they're virtually gone in 3 days. My plants handled it like champs. Survived the drought (dry period, is drought the right word?) and the gnats as well.