Gnats are almost ALWAYS an indication for overwatering, they lay their eggs in moist/wet soil.
Water properly and let the soil dry out between watering...the gnats will go away.
You can in addition also cover the top of your soil with sand, perlite, etc....so that they cannot get in there anymore and lay their eggs.
Also..gnats are "relatively" harmless, they are more a danger for small seedlings.