bergamot-translator/app/bergamot.cpp
Jerin Philip 7099b9e9ad
Streamline memory-bundle loads (#307)
Provides an additional constructor which takes care of the bundle
loading inside the boundary of the source here, when a configuration
file is supplied from a client like translateLocally or python bindings.
Once the config file is read, we have access to the information required
to construct the MemoryBundle.

 - The command-line application supplied from here, app/bergamot is
   configured to use the fast-load path now.
 - Changes to binary-loading additionally revealed a bug in the
   example-run script used in docs and tied to CI and the fix is
   included.
 - Shortlist is made optional in the memory bundle, making changes to
   getModelMemoryFromConfig.

Fixes #304.
Fixes #306.
See also: XapaJIaMnu/translateLocally#82.
2022-01-19 16:36:48 +00:00

42 lines
1.2 KiB
C++

#include "translator/byte_array_util.h"
#include "translator/parser.h"
#include "translator/response.h"
#include "translator/response_options.h"
#include "translator/service.h"
#include "translator/utils.h"
int main(int argc, char *argv[]) {
using namespace marian::bergamot;
ConfigParser<AsyncService> configParser("Bergamot CLI", /*multiOpMode=*/false);
configParser.parseArgs(argc, argv);
auto &config = configParser.getConfig();
AsyncService service(config.serviceConfig);
// Construct a model.
auto options = parseOptionsFromFilePath(config.modelConfigPaths.front());
std::shared_ptr<TranslationModel> model = service.createCompatibleModel(options);
ResponseOptions responseOptions;
std::string input = readFromStdin();
// Create a barrier using future/promise.
std::promise<Response> promise;
std::future<Response> future = promise.get_future();
auto callback = [&promise](Response &&response) {
// Fulfill promise.
promise.set_value(std::move(response));
};
service.translate(model, std::move(input), callback, responseOptions);
// Wait until promise sets the response.
Response response = future.get();
// Print (only) translated text.
std::cout << response.target.text;
return 0;
}