-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinfer_code_python.py
More file actions
55 lines (45 loc) · 1.08 KB
/
infer_code_python.py
File metadata and controls
55 lines (45 loc) · 1.08 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import requests
import json
# Triton server URL
url = "http://localhost:8000/v2/models/model_onemtbig/infer"
# Take user input
source_text = "My name is Vandan"
model_id = "1"
source_lang = "en"
target_lang = "hi"
# Request payload
input_data = {
"input": [{"source": source_text}],
"config": {
"modelId": model_id,
"language": {
"sourceLanguage": source_lang,
"targetLanguage": target_lang
}
}
}
payload = {
"inputs": [
{
"name": "INPUT_JSON",
"shape": [1, 1],
"datatype": "BYTES",
"data": [json.dumps(input_data)]
}
]
}
# Headers
headers = {
"Content-Type": "application/json"
}
# Print Input JSON
print("=== Input Request ===")
print(json.dumps(input_data, indent=4, ensure_ascii=False))
# Send request
response = requests.post(url, headers=headers, json=payload)
# Parse response
output_data = response.json()
output = json.loads(output_data['outputs'][0]['data'][0])
# Print Output JSON
print("\n=== Output Response ===")
print(json.dumps(output, indent=4))