As several others have stated, I've had success with (food grade) diatomaceous earth. I just keep it in a glass bottle, with parmesan cheese type shaker top screwed on. After each watering, I just lightly powder the surface of the soil, and it really works. Also, if the powder gets wet, I do it again lightly after the soil dries out a bit because the DE works when dry. The gnats are no longer buzzing about.
Windowsill Garden also wrote that she used Hydrogen Peroxide, mixed 1 part to 4 parts water, if I remember her proportions right, when watering. Not only is this healthy for the plant and roots, but it also kills the gnat eggs.
Wishing you the best in getting rid of the pests, LJ