Hiding collections in product gallery if there are no products displayed

Hi everyone, this is a product gallery I am building. Any ideas on how to make filter options disappear if there are no related products aft