Brother, it's very simple... first measure, avoid excess moisture in the substrate... second measure, and very simple, place those yellow sticky strips for the flies and you'll see that a bunch of the smaller ones will get stuck, third and more drastic, some Neem sprays but be very careful with that, when you're already in flowering, don't even think about spraying Neem on the buds whether they are still small or already developed... Neem is very active and harsh and will ruin the quality of the smoke and burn the pistils. So this way you have a solution to your problems with gnats, which are probably not the worst of pests but it's definitely annoying to see them buzzing around the base of the grow.