Skip to content

Commit

Permalink
Merge pull request #77 from ai-cfia/76-enhance-datastore-include-mode…
Browse files Browse the repository at this point in the history
…l-in-json

Fixes #76: Enhance Data Storage: Including Model Details in the result.json file
  • Loading branch information
Maxence Guindon authored Apr 24, 2024
2 parents 7c8f4c7 + 5b8698d commit 6591d12
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ backend to function, you will need to add the missing values:
accepted by the backend
- **NACHET_VALID_DIMENSION**: Contains the valid dimensions for an image to be
accepted in the backend.
- **NACHET_MAX_CONTENT_LENGTH**: Set the maximum size of the file that can be
uploaded to the backend. Needs to be the same size as the
`client_max_body_size`
[value](https://github.com/ai-cfia/howard/blob/dedee069f051ba743122084fcb5d5c97c2499359/kubernetes/aks/apps/nachet/base/nachet-ingress.yaml#L13)
set from the deployment in Howard.

#### DEPRECATED

Expand Down
28 changes: 13 additions & 15 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,6 @@ class MaxContentLengthWarning(APIWarnings):

NACHET_DATA = os.getenv("NACHET_DATA")

Model = namedtuple(
'Model',
[
'entry_function',
'name',
'endpoint',
'api_key',
'inference_function',
'content_type',
'deployment_platform',
]
)

try:
VALID_EXTENSION = json.loads(os.getenv("NACHET_VALID_EXTENSION"))
VALID_DIMENSION = json.loads(os.getenv("NACHET_VALID_DIMENSION"))
Expand Down Expand Up @@ -115,6 +102,7 @@ class MaxContentLengthWarning(APIWarnings):
[
'request_function',
'name',
'version',
'endpoint',
'api_key',
'content_type',
Expand Down Expand Up @@ -371,7 +359,9 @@ async def inference_request():
container_client, folder_name, image_bytes, hash_value
)

for idx, model in enumerate(pipelines_endpoints.get(pipeline_name)):
pipeline = pipelines_endpoints.get(pipeline_name)

for idx, model in enumerate(pipeline):
print(f"Entering {model.name.upper()} model") # TODO: Transform into logging
result_json = await model.request_function(model, cache_json_result[idx])
cache_json_result.append(result_json)
Expand All @@ -383,7 +373,7 @@ async def inference_request():
cache_json_result[-1], imageDims, area_ratio, color_format
)

result_json_string = json.dumps(processed_result_json)
result_json_string = await record_model(pipeline, processed_result_json)

# upload the inference results to the user's container as async task
app.add_background_task(
Expand Down Expand Up @@ -455,6 +445,7 @@ async def test():
m = Model(
request_function["test"],
"test_model1",
1,
"http://localhost:8080/test_model1",
"test_api_key",
"application/json",
Expand All @@ -465,6 +456,12 @@ async def test():

return CACHE["endpoints"], 200


async def record_model(pipeline: namedtuple, result: list):
new_entry = [{"name": model.name, "version": model.version} for model in pipeline]
result[0]["models"] = new_entry
return json.dumps(result, indent=4)


async def fetch_json(repo_URL, key, file_path):
"""
Expand Down Expand Up @@ -505,6 +502,7 @@ async def get_pipelines(connection_string, pipeline_blob_name, pipeline_version,
m = Model(
request_function.get(model.get("endpoint_name")),
model.get("model_name"),
model.get("version"),
# To protect sensible data (API key and model endpoint), we encrypt it when
# it's pushed into the blob storage. Once we retrieve the data here in the
# backend, we need to decrypt the byte format to recover the original
Expand Down
3 changes: 2 additions & 1 deletion tests/test_inference_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ def test_inference_request_successful(self, mock_container):
"score",
"topN",
"overlapping",
"overlappingIndices"
"overlappingIndices",
"models"
}

# Test the answers from inference_request
Expand Down

0 comments on commit 6591d12

Please sign in to comment.