Traducir texto
Con flask de python:
from flask import Flask, request import subprocess app = Flask(__name__) @app.route('/translate', methods=['POST']) def translate(): input_text = request.form['input_text'] lang_pair = request.form['lang_pair'] # Llamada a Apertium para la traducción cmd = ['apertium', lang_pair] p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = p.communicate(input_text.encode()) output_text = stdout.decode() return output_text if __name__ == '__main__': app.run(debug=True,host='0.0.0.0',port=3000)
Para probarlo:
curl -X POST -d "input_text=Esto es la bomba marinera...." -d "lang_pair=es-en" http://localhost:3000/translate