mirror of
https://github.com/marian-nmt/marian.git
synced 2024-09-17 09:47:34 +03:00
Update python client
This commit is contained in:
parent
585c3f26f0
commit
036693b531
@ -1,14 +1,16 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from __future__ import print_function, unicode_literals, division
|
||||
|
||||
import sys
|
||||
import time
|
||||
import argparse
|
||||
|
||||
from websocket import create_connection
|
||||
|
||||
batchSize = int(sys.argv[1]) if len(sys.argv) > 1 else 1
|
||||
|
||||
|
||||
def translate(batch):
|
||||
ws = create_connection("ws://localhost:1234/translate")
|
||||
def translate(batch, port=8080):
|
||||
ws = create_connection("ws://localhost:{}/translate".format(port))
|
||||
#print(batch.rstrip())
|
||||
ws.send(batch)
|
||||
result = ws.recv()
|
||||
@ -16,16 +18,25 @@ def translate(batch):
|
||||
ws.close()
|
||||
|
||||
|
||||
def parse_args():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-b", "--batch-size", type=int, default=1)
|
||||
parser.add_argument("-p", "--port", type=int, default=8080)
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
batchCount = 0
|
||||
args = parse_args()
|
||||
|
||||
count = 0
|
||||
batch = ""
|
||||
for line in sys.stdin:
|
||||
batchCount = batchCount + 1
|
||||
count += 1
|
||||
batch += line
|
||||
if batchCount == batchSize:
|
||||
translate(batch)
|
||||
batchCount = 0
|
||||
if count == args.batch_size:
|
||||
translate(batch, port=args.port)
|
||||
count = 0
|
||||
batch = ""
|
||||
|
||||
if batchCount:
|
||||
translate(batch)
|
||||
if count:
|
||||
translate(batch, port=args.port)
|
||||
|
Loading…
Reference in New Issue
Block a user