Spaces:
Sleeping
Sleeping
Download utils.py from duythduong/test_api: direct link, hf CLI and curl.
- Browser
- Download file 591 Bytes
-
https://huggingface.co/spaces/duythduong/test_api/resolve/main/utils.py
- Command line
-
hf download hf://spaces/duythduong/test_api/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/duythduong/test_api/resolve/main/utils.py
591 Bytes
| import onnxruntime as ort | |
| import numpy as np | |
| def load_session(path: str) -> ort.InferenceSession: | |
| providers = ['CPUExecutionProvider'] | |
| session = ort.InferenceSession(path, providers=providers) | |
| return session | |
| def infer(inference_session: ort.InferenceSession, input_data: np.array) -> np.array: | |
| input_name = inference_session.get_inputs()[0].name | |
| output_name = inference_session.get_outputs()[0].name | |
| inference_inputs = {input_name: input_data} | |
| outputs = inference_session.run( | |
| [output_name], | |
| inference_inputs | |
| ) | |
| return outputs[0] | |