В настоящее время я разрабатываю конвейер развертывания, который может служить моделью глубокого обучения с обобщением текста, работающей в расширении chrome, которая суммирует выделенный текстовый блок в браузере.
мой простой интерфейс выглядит следующим образом, написанный на чистом javascript
chrome.tabs.executeScript( {
code: "window.getSelection().toString();"
}, function(selection) {
document.write(selection[0]);
var post =
'<form action="http://localhost:8080/client_txt" method="POST" id="hlgt_form">' +
'<input type="hidden" id="hlgt" name="hlgt" value="">' +
'</form>';
document.write(post);
document.getElementById('hlgt').value = selection[0];
// it stores highlights into value of <input>
document.getElementById('hlgt_form').submit();
});
, а мой сервер Express.JS выглядит следующим образом
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const python = require('python-shell');
// define conda specific python
const python_path = '/Users/****/anaconda3/envs/****/bin/python';
// define sysArgs for python script
const mode = "decode";
const data_path = "/Users/****/Downloads/finished_files/chunked/test_000.bin";
const vocab_path = "/Users/****/Downloads/finished_files/vocab";
const log_root = "/Users/****/Downloads";
const exp_name = "pretrained_model_tf1.2.1";
app.use(bodyParser.urlencoded({ extended: true }));
app.post('/client_txt', (req, ) => {
const text = `${req.body.hlgt}`;
console.log(text);
/* python runs in express js */
const options = {
mode: 'text',
pythonPath: python_path,
pythonOptions: ['-u'],
scriptPath: '/Users/****/project/text-summarizer/',
args: [ '--hlgt', text,
'--mode', mode,
'--data_path', data_path,
'--vocab_path', vocab_path,
'--log_root', log_root,
'--exp_name', exp_name,
'--max_enc_steps', 400,
'--max_dec_steps', 120,
'--coverage', 1,
'--single_pass', 1,
'--batch_size', 1,
'--beam_size', 1]
};
//TODO: Get return val from python script not print val
python.PythonShell.run('run_summarization.py',
options,
function (err, results) {
if (err)
throw err;
console.log("\n ## summary ##\n" +
results[results.length-1] + "\n"); // python "print" val stored in results
});
/******************************/
});
const port = 8080;
app.listen(port, () => {
console.log(`Server running on port: ${port}`);
});
Серверная сторона получает опубликованный текстс передней стороны, которая выделена, и передайте его глубокому изучению кода Python с текстом sysarg
.
. result
имеет печатные выходные данные терминала Python, а последняя - текстовая строка, которая суммируется,
Я хотел бы отправить результат обратно клиенту.
Что мне добавить?Возможно ли, пока я продолжаю использовать метод post
?