|
|
import json |
|
|
import os |
|
|
import requests |
|
|
|
|
|
from pathlib import Path |
|
|
from PIL import Image |
|
|
|
|
|
from batch_regression_test import ( |
|
|
INFER_RESPONSE_FUNCTIONS |
|
|
) |
|
|
|
|
|
PORT = os.getenv("PORT", 9001) |
|
|
BASE_URL = os.getenv("BASE_URL", "http://localhost") |
|
|
|
|
|
def main(): |
|
|
|
|
|
|
|
|
|
|
|
with open(os.path.join(Path(__file__).resolve().parent, "batch_tests.json"), "r") as f: |
|
|
tests = json.load(f) |
|
|
|
|
|
|
|
|
for test in tests: |
|
|
if "expected_response" not in test: |
|
|
pil_image = Image.open( |
|
|
requests.get(test["image_url"], stream=True).raw |
|
|
).convert("RGB") |
|
|
test["pil_image"] = pil_image |
|
|
api_key = os.getenv(test["project"].replace("-", "_") + "_API_KEY") |
|
|
|
|
|
test["expected_response"] = dict() |
|
|
for response_function in INFER_RESPONSE_FUNCTIONS: |
|
|
response, image_type = response_function( |
|
|
test, port=PORT, api_key=api_key, base_url=BASE_URL, batch_size=test["batch_size"] |
|
|
) |
|
|
try: |
|
|
response.raise_for_status() |
|
|
test["expected_response"][image_type] = response.json() |
|
|
except Exception as e: |
|
|
print(response.text) |
|
|
|
|
|
if "expected_response" in test: |
|
|
del test["expected_response"] |
|
|
|
|
|
del test["pil_image"] |
|
|
|
|
|
|
|
|
with open(os.path.join(Path(__file__).resolve().parent, "batch_tests.json"), "w") as f: |
|
|
json.dump(tests, f, indent=4) |
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
main() |
|
|
|