document-translator / src /mtuoc_aina_translator.py
mjuvilla's picture
integrated any-doc into the gradle app, separated the translation side to make it easier to implement other translation models
6e54822
raw
history blame
520 Bytes
import requests
import json
from nltk.tokenize import sent_tokenize
class MTUOCAinaTranslator:
def __init__(self, ip: str, port: str):
self.ip = ip
self.port = port
def translate(self, text):
stuff = sent_tokenize(text)
myobj = {
'id': '1',
'src': text,
}
url = 'http://' + self.ip + ':' + self.port + '/translate'
x = requests.post(url, json=myobj)
json_response = json.loads(x.text)
return json_response['tgt']