Diatomaceous Earth.
I had gnat issues in my last grow during veg. Had six Great White Shark feminized going and gnats began to appear after a slight over-water in a peat based soil that didn't have enough perlite in it for proper drainage at the beginning of week 2.
You need to raise temp and/or air flow a bit and let soil dry out the top 1-2", apply DE with fans off using some type of scoop, making sure you cover every single inch of the exposed soil or as much of it as you can. One can then keep air flow strength low and stream high in order not to blow this stuff all over, this is what I did.
DE won't hurt anything other than your lungs, but, government tests have said one would have to work around DE without a mask for many years before any damage to lungs would begin. Just don't breath in the dust when applying, fairly simple. Any flakes floating around after application are harmless, it's the dust that comes off this stuff when you move it that's bad, but again, it would take many years of breathing in to have a negative effect on you, much like perlite and vermiculite dust.
Or you can top the DE with hydro balls or a very light coating of sand so you don't have to turn airflow down.
Let your soil dry out completely, this is good for most healthy strains and should not harm them, it promotes root growth to a point. Any adults that get through hydro balls or sand if you use either, will meet a quick death from DE as it literally tears them apart, same goes for any leaving the soil. During this time the soil is drying, this will kill any larvae that exists in the soil. Eggs hatch within 4 days, so once you apply DE this is when you begin the countdown. Apply DE, do not water for 5-7 days, during this time use yellow sticky strips or other means to trap and kill any adults not entering soil. This is important, because if you do all this work with the DE and don't rid your room of adults that are not entering the soil you will just have issues again, probably right after your next watering.
It's not the funnest process in the world but it works. One smaller bag was around 15 dollars, for six 5 gal buckets I used only half of it so it's not an expensive solution.