-
Notifications
You must be signed in to change notification settings - Fork 4
/
client.py
40 lines (37 loc) · 1.46 KB
/
client.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import argparse
import requests
import urllib.parse
import json
parser = argparse.ArgumentParser(description='PyTorch Language Model')
parser.add_argument('--host', type=str, default='http://localhost',
help='host name')
parser.add_argument('--port', type=int, default='8888',
help='access port number')
parser.add_argument('--path', type=str, default='lm',
help='path')
if __name__ == '__main__':
args = parser.parse_args()
url = args.host + ":" + str(args.port) + "/" + args.path
headers = {
'Content-Type': 'application/json',
}
data = {
"sentences" : [
"This is a test post .",
"Can you calculate a perplexity of this text ?",
"If you encounter an error , please report it to us .",
"This is a test post .",
"Can you calculate a perplexity of this text ?",
"If you encounter an error , please report it to us .",
"This is a test post .",
"Can you calculate a perplexity of this text ?",
"If you encounter an error , please report it to us .",
"This is a test post .",
"Can you calculate a perplexity of this text ?",
"If you encounter an error , please report it to us ."
]
}
r = urllib.request.Request(url, json.dumps(data).encode(), headers)
with urllib.request.urlopen(r) as res:
body = json.load(res)
print(body)