new(all): General Bots reading comprehension.

This commit is contained in:
Rodrigo Rodriguez 2021-07-13 12:47:06 -03:00
parent 7dd58fa38f
commit 05e1466355
5 changed files with 89 additions and 9 deletions

View file

@ -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.",

34
GeneralQA/__init__.py Normal file
View file

@ -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
)

20
GeneralQA/function.json Normal file
View file

@ -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"
}
]
}

View file

@ -10,6 +10,6 @@
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[1.*, 2.0.0)"
"version": "[2.*, 3.0.0)"
}
}

View file

@ -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
numpy
allennlp
allennlp-models
nltk