Diatomaceous earth is a natural pesticide made from the fossils of small algae organisms, known as diatoms. It will draw moisture from the gnats' bodies, gradually killing them.
With a face mask and gloves spread food-grade diatomaceous earth over the soil when it's dry. If the dirt is moist, the pesticide might not work properly.
When using diatomaceous earth, water your plants from the bottom so it does not absorb any water. The gnats will start to disappear in a week and likely be gone in a few weeks.