Hi,
I have a server.py running at the port number 7790 :
administrator@:~/OpenNMT/OpenNMT-py$ python3 server.py --ip “0.0.0.0” --port “7790” --url_root “/translator” --config "./available_models/conf_pyonmttok.json"
Pre-loading model 1
[2019-07-30 15:58:13,899 INFO] Loading model 1
[2019-07-30 15:58:23,680 INFO] Loading tokenizer
Pre-loading model 0
- Serving Flask app “server” (lazy loading)
- Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead. - Debug mode: off
[2019-07-30 15:58:23,806 INFO] * Running on http://0.0.0.0:7790/ (Press CTRL+C to quit)
The client for getting response for GER-ENG translation is :
import requests
def translate_de_en():
** url = “http://0.0.0.0:7790/translator/translate”**
** ans = ‘y’**
** while ans is ‘y’ :**
** source = input("Enter the sentence ==> ")**
** if not source:**
** #print("")**
** return “”**
** headers = {‘content-type’:‘application/json’}**
** params = [{“src”:source, “id”:1}]**
** response = requests.post(url, json=params, headers=headers)**
** target = response.json()**
** print(target[0][0][“tgt”])**
** ans = input(“Do you want to continue: y or n ?”)**
if name == “main”:
** translate_de_en()**
When I run the client for getting the response, I get the following error message:
administrator@~/OpenNMT$ python3 translate_de_en.py
Enter the sentence ==> Hallo Welt
Traceback (most recent call last):
File “translate_de_en.py”, line 30, in
translate_de_en()
File “translate_de_en.py”, line 23, in translate_de_en
print(target[0][0][“tgt”])
KeyError: 0
administrator@~/OpenNMT$
Please guide me what part of response should be taken for printing the output text.
Thank You,
Kishor.