import sys import codecs import requests import json from tqdm import tqdm import glob url = "http://ssmt.iiit.ac.in/onemt" headers = { 'Content-Type': 'application/json', 'Accept': 'application/json' } def call_mt(text, lang='eng', Tlang='hin'): data = {'text': text, 'lang':lang, 'Tlang':Tlang, "mode": "BaseLine - V5"} r = requests.post(url, headers=headers, json=data) output = json.loads(r.text)['data'] return output source_file = sys.argv[1] output_file = sys.argv[2] def read_file(path, isref=False): _data = [] for line in codecs.open(path, encoding="utf8"): line = line.strip() line = line.replace('_','').replace('`','').replace('"','').replace("'",'') _data.append(line) return _data _data_source = read_file(source_file) _data_sys = [call_mt(text, 'tel', 'hin').replace('\n',' ') for text in tqdm(_data_source)] _f = open(output_file, 'w', encoding="utf8") for line in _data_sys: _f.write(line+'\n') print (line) _f.close()