The entire script can be split into 4 modules named train_dqn.py, agent_reply_dqn.py, test_dqn.py and hyperparameters_dqn.py. Store these in a folder of your choice, say chapter_15. Set chapter_15 as the project folder in your favorite source code editor and just run the file train_dqn.py.
The train_dqn.py python file will import functions from all the other modules in places where needed for execution.
Now let's walk through the contents of each file.