Nowadays, the power quality (PQ)-related issues have become more prominent in power electronic devices. For compensating PQ disturbances various types of power devices are used. The unified power quality conditioner (UPQC) is one of the power electronic devices that is used for compensating the PQ. To reduce the PQ disturbances, the performance of series and shunt active power filters (APFs) must be improved. In this paper, an enhanced controller is proposed for improving the performance of series and shunt APFs and compensating the PQ. The enhanced technique used is the combination of artificial neural network (ANN) and gravitational search algorithm (GSA) which is used for generating the control signals of the APF and reducing the PQ problem. The shunt APF is used for reducing the harmonic disturbances. The DC-link voltage is regulated by utilizing the proposed enhanced controller technique. Subsequently, the THD value of the proposed system is measured. The proposed method is implemented in MATLAB/Simulink platform and its performance is evaluated. The performance of the proposed method is evaluated and compared with the base controller and ANN controller.