You can get rid of fruit flies by making a homemade fruit fly trap with a jar and plastic wrap.
Mix some apple cider vinegar with a little bit of dish soap and put it in the jar and then cover the jar with the plastic wrap.
Poke a few tiny holes into the plastic wrap to allow the fruit flies to get into the jar but not large enough to where they can fly out.
You can also place some banana slices or other fruit slices in a jar and cover it with the plastic wrap as well with the holes and the fruit flies will go into the jar after the fruit and will be trapped in the jar.
Red wine in a jar will also trap and kill fruit flies as well as get rid of gnats.