once a gnat is matured and flying around, they don't eat. The problem is the larva and the damage they cause to the roots. Get "Bti" product in your region, if it exists. sticky traps for adults. In future, use Bti preemptively and avoid the problem before it starts. if you see bite marks with honeydew around the damage, that's something else. Bti will only help with larva in the medium. Mosquito Bits is the brand name in my area.. but the active ingredient is what matters, not the brand. It's a bacteria that's been used on world food crops for over a century so you know it is safe. Since it's a top dress or somethign you toss in the reservoir, you can use in vege or flower with no problems.
If you have honeydew around edges of the bit marks that is something different. May need a pyrethine - kills on contact and can take care of most pests. Do not spray on flower, of course. You'll need a pesticide of some sort for that sort of issue.