-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.py
26 lines (17 loc) · 832 Bytes
/
demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Author: Suprateem Banerjee [www.github.com/suprateembanerjee]
# Usage: python demo.py "I have never heard her speak english"
import os, argparse
import requests
def translate_to_spanish(sentence:str) -> str:
url = 'http://localhost:5000/translate'
myobj = {'text': sentence,
'source_vectorization': 'models/english_vectorization.pkl',
'target_vectorization': 'models/spanish_vectorization.pkl',
'model': 'models/translator_transformer.keras'}
message = requests.post(url, json = myobj).json()
return message['translated']
if __name__=='__main__':
parser = argparse.ArgumentParser(description='English to Spanish Translator')
parser.add_argument('input_sentence', type=str, help='English sentence')
args = parser.parse_args()
print(' '.join(translate_to_spanish(args.input_sentence).split()[1:-1]))