Just to add a little bit to the excellent answer from Ekaterina,
Generating text that follows a cohesive story is very hard.
For snippets or verses the challenge is much smaller and you can get some good results, for a Harry Potter book it would be very hard (if even possible at this time).