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...

2 Replies to “Machine Translation Web Interface for OpenNMT”

  1. Hello Yasmin,

    Good work.
    I have a few question:
    The initial “” is near empty and it must be edited before use?
    Where can I found examples or finished ones?
    The “” looks like a finish “”. My framework run and I train models a.s.o. but the problem for me is to run the GUI and to attach my created models behind.
    Thanks a lot for Information!

    No votes yet.
    Please wait...
    1. Dear Leon,

      Thanks for your comment!

      The OpenNMT-py file is NOT empty; it imports onmt.bin.server – there you can see all the code. You do NOT have to change anything. is something completely different; it is for running a Flask GUI. You just have to make sure that the url variable is correct.

      The instructions that you have to follow are explained by Paul Tardy at:

      Once you have the server running, just use the url in

      Also, you can keep language = "en-fr" as is or change it; however, if you change it in, you have to change it in index.html as well.

      I hope this helps.

      All the best,

      Rating: 5.0/5. From 1 vote.
      Please wait...

Leave a Reply

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