From 8e6543f0b65cd882d3624744ed8c8745a7087198 Mon Sep 17 00:00:00 2001 From: Rodrigo Rodriguez Date: Tue, 13 Jul 2021 16:15:36 -0300 Subject: [PATCH] new(all): Removal of Azure Functions and migration to Flesk. --- .funcignore | 5 --- .gitignore | 55 ++++++++++++++++++++++++------ .vscode/extensions.json | 6 ---- .vscode/launch.json | 12 ------- .vscode/settings.json | 9 ++--- .vscode/tasks.json | 26 -------------- EstimateLoanTax/__init__.py | 51 --------------------------- EstimateLoanTax/function.json | 20 ----------- EstimateLoanTax/sample.dat | 3 -- EstimateLoanTaxTrain/__init__.py | 17 --------- EstimateLoanTaxTrain/function.json | 20 ----------- EstimateLoanTaxTrain/sample.dat | 3 -- GeneralQA/function.json | 20 ----------- README.md | 19 +---------- GeneralQA/__init__.py => app.py | 29 +++++++++++----- host.json | 15 -------- proxies.json | 4 --- requirements.txt | 2 ++ templates/index.html | 14 ++++++++ 19 files changed, 84 insertions(+), 246 deletions(-) delete mode 100644 .funcignore delete mode 100644 .vscode/extensions.json delete mode 100644 .vscode/launch.json delete mode 100644 .vscode/tasks.json delete mode 100644 EstimateLoanTax/__init__.py delete mode 100644 EstimateLoanTax/function.json delete mode 100644 EstimateLoanTax/sample.dat delete mode 100644 EstimateLoanTaxTrain/__init__.py delete mode 100644 EstimateLoanTaxTrain/function.json delete mode 100644 EstimateLoanTaxTrain/sample.dat delete mode 100644 GeneralQA/function.json rename GeneralQA/__init__.py => app.py (55%) delete mode 100644 host.json delete mode 100644 proxies.json create mode 100644 templates/index.html diff --git a/.funcignore b/.funcignore deleted file mode 100644 index 0678ea2..0000000 --- a/.funcignore +++ /dev/null @@ -1,5 +0,0 @@ -.git* -.vscode -local.settings.json -test -.venv \ No newline at end of file diff --git a/.gitignore b/.gitignore index a10127b..5de65cf 100644 --- a/.gitignore +++ b/.gitignore @@ -20,7 +20,6 @@ parts/ sdist/ var/ wheels/ -pip-wheel-metadata/ share/python-wheels/ *.egg-info/ .installed.cfg @@ -47,8 +46,10 @@ htmlcov/ nosetests.xml coverage.xml *.cover +*.py,cover .hypothesis/ .pytest_cache/ +cover/ # Translations *.mo @@ -58,6 +59,7 @@ coverage.xml *.log local_settings.py db.sqlite3 +db.sqlite3-journal # Flask stuff: instance/ @@ -70,6 +72,7 @@ instance/ docs/_build/ # PyBuilder +.pybuilder/ target/ # Jupyter Notebook @@ -80,17 +83,23 @@ profile_default/ ipython_config.py # pyenv -.python-version +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version # pipenv # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. # However, in case of collaboration, if having platform-specific dependencies or dependencies -# having no cross-platform support, pipenv may install dependencies that don’t work, or not +# having no cross-platform support, pipenv may install dependencies that don't work, or not # install all needed dependencies. #Pipfile.lock -# celery beat schedule file +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff celerybeat-schedule +celerybeat.pid # SageMath parsed files *.sage.py @@ -122,9 +131,35 @@ dmypy.json # Pyre type checker .pyre/ -# Azure Functions artifacts -bin -obj -appsettings.json -local.settings.json -.python_packages \ No newline at end of file +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk diff --git a/.vscode/extensions.json b/.vscode/extensions.json deleted file mode 100644 index cbbad0f..0000000 --- a/.vscode/extensions.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "recommendations": [ - "ms-azuretools.vscode-azurefunctions", - "ms-python.python" - ] -} diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 0e43bd3..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "version": "0.2.0", - "configurations": [ - { - "name": "Attach to Python Functions", - "type": "python", - "request": "attach", - "port": 9091, - "preLaunchTask": "func: host start" - } - ] -} diff --git a/.vscode/settings.json b/.vscode/settings.json index 615c689..988937c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,8 +1,3 @@ { - "azureFunctions.deploySubpath": ".", - "azureFunctions.scmDoBuildDuringDeployment": true, - "azureFunctions.pythonVenv": ".venv", - "azureFunctions.projectLanguage": "Python", - "azureFunctions.projectRuntime": "~3", - "debug.internalConsoleOptions": "neverOpen" -} + "python.pythonPath": "/usr/local/bin/python3" +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json deleted file mode 100644 index 593bc21..0000000 --- a/.vscode/tasks.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "version": "2.0.0", - "tasks": [ - { - "type": "func", - "command": "host start", - "problemMatcher": "$func-python-watch", - "isBackground": true, - "dependsOn": "pipInstall" - }, - { - "label": "pipInstall", - "type": "shell", - "osx": { - "command": "${config:azureFunctions.pythonVenv}/bin/python -m pip install -r requirements.txt" - }, - "windows": { - "command": "${config:azureFunctions.pythonVenv}\\Scripts\\python -m pip install -r requirements.txt" - }, - "linux": { - "command": "${config:azureFunctions.pythonVenv}/bin/python -m pip install -r requirements.txt" - }, - "problemMatcher": [] - } - ] -} diff --git a/EstimateLoanTax/__init__.py b/EstimateLoanTax/__init__.py deleted file mode 100644 index 7516ad3..0000000 --- a/EstimateLoanTax/__init__.py +++ /dev/null @@ -1,51 +0,0 @@ -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.') - - age = req.params.get('age') - income = req.params.get('income') - employeeTime = req.params.get('employeeTime') - - # Code here. - - returnedTax = 1; - - 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.", - status_code=200 - ) diff --git a/EstimateLoanTax/function.json b/EstimateLoanTax/function.json deleted file mode 100644 index 8c4cbe3..0000000 --- a/EstimateLoanTax/function.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "scriptFile": "__init__.py", - "bindings": [ - { - "authLevel": "anonymous", - "type": "httpTrigger", - "direction": "in", - "name": "req", - "methods": [ - "get", - "post" - ] - }, - { - "type": "http", - "direction": "out", - "name": "$return" - } - ] -} diff --git a/EstimateLoanTax/sample.dat b/EstimateLoanTax/sample.dat deleted file mode 100644 index 26aac46..0000000 --- a/EstimateLoanTax/sample.dat +++ /dev/null @@ -1,3 +0,0 @@ -{ - "name": "Azure" -} \ No newline at end of file diff --git a/EstimateLoanTaxTrain/__init__.py b/EstimateLoanTaxTrain/__init__.py deleted file mode 100644 index 44d3915..0000000 --- a/EstimateLoanTaxTrain/__init__.py +++ /dev/null @@ -1,17 +0,0 @@ -import logging - -import azure.functions as func - - -def main(req: func.HttpRequest) -> func.HttpResponse: - logging.info('Python HTTP trigger function processed a request.') - - name = req.params.get('name') - - if name: - return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.") - 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/EstimateLoanTaxTrain/function.json b/EstimateLoanTaxTrain/function.json deleted file mode 100644 index 8c4cbe3..0000000 --- a/EstimateLoanTaxTrain/function.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "scriptFile": "__init__.py", - "bindings": [ - { - "authLevel": "anonymous", - "type": "httpTrigger", - "direction": "in", - "name": "req", - "methods": [ - "get", - "post" - ] - }, - { - "type": "http", - "direction": "out", - "name": "$return" - } - ] -} diff --git a/EstimateLoanTaxTrain/sample.dat b/EstimateLoanTaxTrain/sample.dat deleted file mode 100644 index 26aac46..0000000 --- a/EstimateLoanTaxTrain/sample.dat +++ /dev/null @@ -1,3 +0,0 @@ -{ - "name": "Azure" -} \ No newline at end of file diff --git a/GeneralQA/function.json b/GeneralQA/function.json deleted file mode 100644 index 8c4cbe3..0000000 --- a/GeneralQA/function.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "scriptFile": "__init__.py", - "bindings": [ - { - "authLevel": "anonymous", - "type": "httpTrigger", - "direction": "in", - "name": "req", - "methods": [ - "get", - "post" - ] - }, - { - "type": "http", - "direction": "out", - "name": "$return" - } - ] -} diff --git a/README.md b/README.md index 7b93ae1..d79ddb3 100644 --- a/README.md +++ b/README.md @@ -1,18 +1 @@ -# BotModels - -Models in Python for General Bots AI demands. - -# Environment - - 1. Install Visual Studio Code (VSCode); - 2. Install VSCode Extension: Azure Functions; - 3. Install VSCode Extension: Azure Machine Learning; - 4. Install NodeJS; - 5. Run npm install -g azure-functions-core-tools@3 --unsafe-perm true. - -# Libraries - -- TensorFlow; -- SciKit-Learn; -- Pandas; -- NumPy. +This is sample Python Flask application. \ No newline at end of file diff --git a/GeneralQA/__init__.py b/app.py similarity index 55% rename from GeneralQA/__init__.py rename to app.py index 88de01e..31d9f3a 100644 --- a/GeneralQA/__init__.py +++ b/app.py @@ -9,12 +9,22 @@ import json predictor = None -def main(req: func.HttpRequest) -> func.HttpResponse: +from flask import Flask, render_template, request +import hmac + +app = Flask(__name__) + +@app.route("/query", methods=['POST']) +def index(): logging.info('General Bots QA.') - content = req.form.get('content') - question = req.params.get('question') - + content = request.form.get('content') + question = request.args.get('question') + key = request.args.get('key') + + if not hmac.compare_digest(key, 'starter'): + return 'Invalid key.' + global predictor if predictor is None: predictor = Predictor.from_path("https://storage.googleapis.com/allennlp-public-models/transformer-qa-2020-10-03.tar.gz") @@ -26,9 +36,10 @@ def main(req: func.HttpRequest) -> func.HttpResponse: if answer: - return func.HttpResponse(answer) + return 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 - ) + return "No answers for this question." + +if __name__ == '__main__': + app.run(debug=True) + \ No newline at end of file diff --git a/host.json b/host.json deleted file mode 100644 index 3f33af1..0000000 --- a/host.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "version": "2.0", - "logging": { - "applicationInsights": { - "samplingSettings": { - "isEnabled": true, - "excludedTypes": "Request" - } - } - }, - "extensionBundle": { - "id": "Microsoft.Azure.Functions.ExtensionBundle", - "version": "[2.*, 3.0.0)" - } -} diff --git a/proxies.json b/proxies.json deleted file mode 100644 index b385252..0000000 --- a/proxies.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "$schema": "http://json.schemastore.org/proxies", - "proxies": {} -} diff --git a/requirements.txt b/requirements.txt index 0bcb5d1..b39667b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,3 +8,5 @@ numpy allennlp allennlp-models nltk +Flask>=1.0,<=1.1.2 +hashlib diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..0bd56af --- /dev/null +++ b/templates/index.html @@ -0,0 +1,14 @@ + + + + + + Azure Web Apps + + + + +

Welcome to Azure Web Apps!!

+ + + \ No newline at end of file