A neural-network machine learning model is developed to control a bimorph adaptive mirror to achieve and preserve aberration-free coherent X-ray wavefronts at synchrotron radiation and free electron laser beamlines. The controller is trained on a mirror actuator response directly measured at a beamline with a real-time single-shot wavefront sensor, which uses a coded mask and wavelet-transform analysis. The system has been successfully tested on a bimorph deformable mirror at the 28-ID IDEA beamline of the Advanced Photon Source at Argonne National Laboratory. It achieved a response time of a few seconds and maintained desired wavefront shapes (e.g., a spherical wavefront) with sub-wavelength accuracy at 20 keV of X-ray energy. This result is significantly better than what can be obtained using a linear model of the mirror's response. The developed system has not been tailored to a specific mirror and can be applied, in principle, to different kinds of bending mechanisms and actuators.