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
at: Simple OpenNMT-py REST server.
You can find the code of the machine translation web interface at:
If something is not covered by the tokenizer, you can apply your own pre-processing code on the text entered in the textarea, and even later your post-processing code on the text received from the translation server. As you know, you can put the text you receive in either cases in a string variable and apply any code on this variable.
I have used and slightly adapted Yasmin’s interface which works very nicely. It’s a great contribution. It can also be seen in action at our free NMT service at www.nmtgateway.com.
even later your post-processing code on the text received from the translation server. can yougive an exxample of what to put here instead of getting this error "raise JSONDecodeError(“Expecting value”, s, err.value) from None
"
Hi Sheila! I wonder why you receive None in the first place. Does your server work in the Terminal, outside of the code? I mean try to test it first in your Terminal/CMD using the command line mentioned at: Simple OpenNMT-py REST server
I’ve implemented the REST server mentioned above,
but I don’t have a clue how to run the web interface.
Do I just have to run the server and do “python mt.py” in another server?
Which website do I have to go to check the interface?
However, if you are just doing a quick assignment or a temporary test, you can use something like PythonAnywhere or Heroku. The main reason why I did not use PythonAnywhere is that, even with a paid plan, it has a time limitation for running scripts, which does not help for a REST server as you need it to be running 24/7. I do not know about Heroku with this regard.
It is worth mentioning as well that free plans of any server have space limitations. Recently, a colleague contacted me asking how reduce the size of their model, and the answer was to use Model Averaging, which can reduce the size of a model to 1/3 of its original size; for OpenNMT-py, there is a script called average_models.py under the “tools” folder.
Hi! I’m John, I’ve already made an account for this forum. I saw your answer to @SoYoungCho, and I’ve the same problem as you know Yasmin… I don’t understand the apache server part, if I mount that, how am I supposed to connect that server with for example heroku?.
It would be so wonderfull if there were a tutorial to deploy our rest server to production…
As I mentioned, I am using DigitalOcean, that is why I am having an Apache server. However, if you are using PythonAnywhere or Heroku, they are prepared to deploy Python apps directly.
You will run the command from the Terminal/command line: python3 OpenNMT-py/server.py --ip "0.0.0.0" --port 5000 --url_root "/translator" --config available_models/conf.json
In the mt.py Python file, do not change the URL that I provided; it is: url = "http://127.0.0.1:5000/translator/translate"
Now, you use the mt.py file (with the “templates” folders I provided) as your Heroku app. This official tutorial, explains how to deploy a Python app on Heroku.
Hello John,
The code is not generic yet, so you will have to make changes to index.html, form.js and process.py to fit your needs.
I am using the free hosting plan so there are some limitations, but here are the steps as I recall:
Create the directories and upload the files one by one:
hey guys??? Anyone with step-by-step instructions on how I can get my OpenNMT translation app online. I t works perfectly well on my machine but I have no idea to make online