Machine Translation Web Interface for OpenNMT

You might want to build a GUI for your Machine Translation model to show to a client or to be able to translate sentences online. I have created a simple web interface for OpenNMT which depends on Python Flask and Flask-PageDown libraries.

To be able to use the web interface, you need first to implement an OpenNMT Rest API Server as explained by Paul Tardy in his tutorial, Simple OpenNMT-py REST server. Then, you can use the web interface to route the translation requests to the REST server that hosts your OpenNMT models.

You can find the code of the machine translation web interface at:

You need to modify the code adding the REST server url of your language pair. You can also apply your own tokenization or pre-processing on the source and post-processing on the output text as you need.

Feel free to check my live implementation of this web interface at

If you have questions, please let me know.


  • Splitting sentences using NLTK’s sent_tokenize() function, and translating them sentence by sentence, and then joining the outputs.
  • True-casing the translation, i.e. retrieving capitalization of entity names and first word, using the Python library TrueCase‘s get_true_case() function. For example, try to translate the following sentence in my French-English (International Organizations) model: “Nous remercions le Commissaire de l’Union africaine, M Lamamra, de sa d├ęclaration.” and the output will be: “We thank the African Union Commissioner, Mr. Lamamra, for his statement.
Rating: 5.0/5. From 2 votes.
Please wait...

Leave a Reply

Your email address will not be published. Required fields are marked *