Back to Parent

Product

In order to still realize my idea of generating text I used the python module textgenrnn which was developed on top of Keras/TensorFlow. With the following four lines of code text could be generated.

---------------------------------------------------------------------------------------------------------------------------

from textgenrnn import textgenrnn

textgen = textgenrnn()

generated_texts = textgen.generate(n=5, prefix="Trump", temperature=0.2, return_as_list=True)

print(generated_texts)

---------------------------------------------------------------------------------------------------------------------------

The textgen.generate function allows to specify a specific amount of sentences ‘n’. For every sentence you create you can allow a specific ‘prefix’. With the input ‘temperate’ you can define the creativity of the algorithm.

For further explanations please checkout: https://github.com/minimaxir/textgenrnn

Running a python script on Heroku requires to set a buildpack. If you already deployed an app to Heroku, your first buildpack is Python. Therefore, add python as second buildpack.

---------------------------------------------------------------------------------------------------------------------------

heroku buildpacks:add --index 2 heroku/python

You can check the order of your buildpacks with the following code:

heroku buildpacks

---------------------------------------------------------------------------------------------------------------------------

Additionally, to adding the buildpack Heroku requires several additional files. Check how to set up a python app on Heroku (In my case the listed additional files were required: Procfile, Procfile.windows, requirements.txt)

To run the python script the ‘open3’ gem was required. Open3 runs the python script and helps to capture the output of a command.

Another problem I encountered was that even when running the pretrained machine learning algorithm the server request timed out.

The idea to solve that issue was to start a thread. A thread is a process that can run in parallel to the core process. If the user is sending a request during processing of the python script, an answer will be sent, telling him to check back later.



Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0