-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes #51: Change model_utilitary_function to model_request module an…
…d update app.py with new imports and function calls
- Loading branch information
Maxence Guindon
committed
Feb 14, 2024
1 parent
560e50f
commit 559c66b
Showing
5 changed files
with
99 additions
and
102 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import json | ||
from urllib.request import Request | ||
|
||
async def request_factory(img_bytes: str | bytes, endpoint_url: str, api_key: str, model_name: str) -> Request: | ||
""" | ||
Args: | ||
img_bytes (str | bytes): The image data as either a string or bytes. | ||
endpoint_url (str): The URL of the AI model endpoint. | ||
api_key (str): The API key for accessing the AI model. | ||
Returns: | ||
Request: The request object for calling the AI model. | ||
""" | ||
headers = { | ||
"Content-Type": "application/json", | ||
"Authorization": ("Bearer " + api_key), | ||
"azureml-model-deployment": model_name, | ||
} | ||
|
||
if isinstance(img_bytes, str): | ||
data = { | ||
"input_data": { | ||
"columns": ["image"], | ||
"index": [0], | ||
"data": [img_bytes], | ||
} | ||
} | ||
body = str.encode(json.dumps(data)) | ||
elif isinstance(img_bytes, bytes): | ||
body = img_bytes | ||
|
||
return Request(endpoint_url, body, headers) |
This file was deleted.
Oops, something went wrong.