diff --git a/EstimateLoanTax/__init__.py b/EstimateLoanTax/__init__.py index c441f91..7516ad3 100644 --- a/EstimateLoanTax/__init__.py +++ b/EstimateLoanTax/__init__.py @@ -1,9 +1,36 @@ +import os import logging - import azure.functions as func +from azure.storage.blob import BlobClient +from tempfile import NamedTemporaryFile +#from azure.storage.blob import BlockBlobService + #set STORAGE_BLOB_URL='https://pythonazurestorage12345.blob.core.windows.net' + +# def get_file(filename): +# local_file = NamedTemporaryFile() +# container_name="datalake" +# BlockBlobService.get_blob_to_stream(container_name, filename, stream=local_file, +# max_connections=2) + +# local_file.seek(0) +# return local_file + +# http://localhost:7071/api/EstimateLoanTax?age=23&income=20000&employeeTime=2 def main(req: func.HttpRequest) -> func.HttpResponse: + + #key = ''; + + # Create the client object for the resource identified by the connection string, + # indicating also the blob container and the name of the specific blob we want. + #blob_client = BlobClient.from_connection_string(key, blob_name="sample.csv") + + # Open a local file and upload its contents to Blob Storage + #with open("./sample.csv", "rb") as data: + # blob_client.upload_blob(data) + + # https://docs.microsoft.com/pt-br/azure/developer/python/azure-sdk-example-storage-use?tabs=cmd logging.info('Python HTTP trigger function processed a request.') @@ -15,8 +42,8 @@ def main(req: func.HttpRequest) -> func.HttpResponse: returnedTax = 1; - if name: - return func.HttpResponse(returnedTax) + if returnedTax: + return func.HttpResponse('1') else: return func.HttpResponse( "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.", diff --git a/GeneralQA/__init__.py b/GeneralQA/__init__.py new file mode 100644 index 0000000..88de01e --- /dev/null +++ b/GeneralQA/__init__.py @@ -0,0 +1,34 @@ +import logging +import azure.functions as func +import os +#os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' +from allennlp.predictors.predictor import Predictor +import json + +# https://ai.google.com/research/NaturalQuestions + +predictor = None + +def main(req: func.HttpRequest) -> func.HttpResponse: + logging.info('General Bots QA.') + + content = req.form.get('content') + question = req.params.get('question') + + global predictor + if predictor is None: + predictor = Predictor.from_path("https://storage.googleapis.com/allennlp-public-models/transformer-qa-2020-10-03.tar.gz") + + answer = predictor.predict( + passage=content, + question=question + )['best_span_str'] + + + if answer: + return func.HttpResponse(answer) + else: + return func.HttpResponse( + "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.", + status_code=200 + ) diff --git a/GeneralQA/function.json b/GeneralQA/function.json new file mode 100644 index 0000000..8c4cbe3 --- /dev/null +++ b/GeneralQA/function.json @@ -0,0 +1,20 @@ +{ + "scriptFile": "__init__.py", + "bindings": [ + { + "authLevel": "anonymous", + "type": "httpTrigger", + "direction": "in", + "name": "req", + "methods": [ + "get", + "post" + ] + }, + { + "type": "http", + "direction": "out", + "name": "$return" + } + ] +} diff --git a/host.json b/host.json index 6ab6643..3f33af1 100644 --- a/host.json +++ b/host.json @@ -10,6 +10,6 @@ }, "extensionBundle": { "id": "Microsoft.Azure.Functions.ExtensionBundle", - "version": "[1.*, 2.0.0)" + "version": "[2.*, 3.0.0)" } } diff --git a/requirements.txt b/requirements.txt index edd2fc2..0bcb5d1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,11 +1,10 @@ -# DO NOT include azure-functions-worker in this file -# The Python Worker is managed by Azure Functions platform -# Manually managing azure-functions-worker may cause unexpected issues - azure-functions azure-storage-blob azure-identity tensorflow scikit-learn pandas -numpy \ No newline at end of file +numpy +allennlp +allennlp-models +nltk