Created
December 10, 2024 20:42
-
-
Save pandeybk/e2e77f53098a0a84f599ac56cf2d5792 to your computer and use it in GitHub Desktop.
notebook.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
def make_request(model_server, input_data, token=None): | |
""" | |
Sends a request to the model server and returns the response. | |
""" | |
headers = {"Content-Type": "application/json"} | |
if token: | |
headers["Authorization"] = f"Bearer {token}" | |
response = requests.post(model_server, headers=headers, data=json.dumps(input_data)) | |
if response.ok: | |
return response.json() | |
else: | |
raise Exception(f"Request failed with status {response.status_code}: {response.text}") | |
MODEL_SERVER = "<model-server>" | |
TOKEN = "<token>" | |
input_data = { | |
"inputs": [ | |
{ | |
"name": "inputs", | |
"shape": [1, 120,1], | |
"datatype": "FP32", | |
"data": [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, | |
1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, | |
2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3.0, | |
3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 4.0, | |
4.1, 4.2, 4.3, 4.4, 4.5, 4.6, 4.7, 4.8, 4.9, 5.0, | |
4.1, 4.2, 4.3, 4.4, 4.5, 4.6, 4.7, 4.8, 4.9, 5.0, | |
0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, | |
1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, | |
2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3.0, | |
3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 4.0, | |
4.1, 4.2, 4.3, 4.4, 4.5, 4.6, 4.7, 4.8, 4.9, 5.0, | |
4.1, 4.2, 4.3, 4.4, 4.5, 4.6, 4.7, 4.8, 4.9, 5.0] | |
} | |
] | |
} | |
try: | |
print("Making request with token...") | |
response_with_token = make_request(MODEL_SERVER, input_data, token=TOKEN) | |
print("Response with token:", response_with_token) | |
except Exception as e: | |
print("Error with token:", e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment