from time import sleep
import json
from flask import Flask, request, abort
from ai4e_app_insights_wrapper import AI4EAppInsights
from ai4e_service import APIService

print('Creating Application')
app = Flask(__name__)

# Use the AI4EAppInsights library to send log messages. NOT REQURIED
log = AI4EAppInsights()

# Use the APIService to executes your functions within a logging trace, supports long-running/async functions,
# handles SIGTERM signals from AKS, etc., and handles concurrent requests.
with app.app_context():
    ai4e_service = APIService(app, log)

# Define a function for processing request data, if applicable.  This function loads data or files into
# a dictionary for access in your API function.  We pass this function as a parameter to your API setup.
def process_request_data(request):
    return_values = {'data': None}
    try:
        # Attempt to load the body
        return_values['data'] = request.get_json()
    except:
        log.log_error('Unable to load the request data')   # Log to Application Insights
    return return_values

# Define a function that runs your model.  This could be in a library.
def run_model(taskId, body):
    # Update the task status, so the caller knows it has been accepted and is running.
Ejemplo n.º 2
0
print('Creating application')

api_prefix = os.getenv('API_PREFIX')
print('API prefix:', api_prefix)
assert api_prefix is not None

app = Flask(__name__)

# Use the AI4EAppInsights library to send log messages. NOT REQUIRED
log = AI4EAppInsights()

# Use the APIService to execute functions within a logging trace, supports
# long-running/async functions, handles SIGTERM signals from AKS, etc., and
# handles concurrent requests.
with app.app_context():
    ai4e_service = APIService(app, log)

# hacking the API Framework a bit, to use some functions directly instead of
# through its decorators in order for the return value of the async call to be
# backwards compatible
api_task_manager = ai4e_service.api_task_manager
ai4e_service.func_request_counts[api_prefix + '/request_detections'] = 0
ai4e_service.func_request_counts[api_prefix + '/request_detections_aml'] = 0

# Instantiate blob storage service to the internal container to put intermediate
# results and files
storage_account_name = os.getenv('STORAGE_ACCOUNT_NAME')
storage_account_key = os.getenv('STORAGE_ACCOUNT_KEY')
assert storage_account_name is not None
assert storage_account_key is not None
internal_storage_service = BlockBlobService(