new(all): Removal of Azure Functions and migration to Flesk.
This commit is contained in:
parent
05e1466355
commit
8e6543f0b6
19 changed files with 84 additions and 246 deletions
|
|
@ -1,5 +0,0 @@
|
||||||
.git*
|
|
||||||
.vscode
|
|
||||||
local.settings.json
|
|
||||||
test
|
|
||||||
.venv
|
|
||||||
55
.gitignore
vendored
55
.gitignore
vendored
|
|
@ -20,7 +20,6 @@ parts/
|
||||||
sdist/
|
sdist/
|
||||||
var/
|
var/
|
||||||
wheels/
|
wheels/
|
||||||
pip-wheel-metadata/
|
|
||||||
share/python-wheels/
|
share/python-wheels/
|
||||||
*.egg-info/
|
*.egg-info/
|
||||||
.installed.cfg
|
.installed.cfg
|
||||||
|
|
@ -47,8 +46,10 @@ htmlcov/
|
||||||
nosetests.xml
|
nosetests.xml
|
||||||
coverage.xml
|
coverage.xml
|
||||||
*.cover
|
*.cover
|
||||||
|
*.py,cover
|
||||||
.hypothesis/
|
.hypothesis/
|
||||||
.pytest_cache/
|
.pytest_cache/
|
||||||
|
cover/
|
||||||
|
|
||||||
# Translations
|
# Translations
|
||||||
*.mo
|
*.mo
|
||||||
|
|
@ -58,6 +59,7 @@ coverage.xml
|
||||||
*.log
|
*.log
|
||||||
local_settings.py
|
local_settings.py
|
||||||
db.sqlite3
|
db.sqlite3
|
||||||
|
db.sqlite3-journal
|
||||||
|
|
||||||
# Flask stuff:
|
# Flask stuff:
|
||||||
instance/
|
instance/
|
||||||
|
|
@ -70,6 +72,7 @@ instance/
|
||||||
docs/_build/
|
docs/_build/
|
||||||
|
|
||||||
# PyBuilder
|
# PyBuilder
|
||||||
|
.pybuilder/
|
||||||
target/
|
target/
|
||||||
|
|
||||||
# Jupyter Notebook
|
# Jupyter Notebook
|
||||||
|
|
@ -80,17 +83,23 @@ profile_default/
|
||||||
ipython_config.py
|
ipython_config.py
|
||||||
|
|
||||||
# pyenv
|
# 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
|
# pipenv
|
||||||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
# 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
|
# 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.
|
# install all needed dependencies.
|
||||||
#Pipfile.lock
|
#Pipfile.lock
|
||||||
|
|
||||||
# celery beat schedule file
|
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
||||||
|
__pypackages__/
|
||||||
|
|
||||||
|
# Celery stuff
|
||||||
celerybeat-schedule
|
celerybeat-schedule
|
||||||
|
celerybeat.pid
|
||||||
|
|
||||||
# SageMath parsed files
|
# SageMath parsed files
|
||||||
*.sage.py
|
*.sage.py
|
||||||
|
|
@ -122,9 +131,35 @@ dmypy.json
|
||||||
# Pyre type checker
|
# Pyre type checker
|
||||||
.pyre/
|
.pyre/
|
||||||
|
|
||||||
# Azure Functions artifacts
|
# pytype static type analyzer
|
||||||
bin
|
.pytype/
|
||||||
obj
|
|
||||||
appsettings.json
|
# Cython debug symbols
|
||||||
local.settings.json
|
cython_debug/
|
||||||
.python_packages
|
|
||||||
|
# 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
|
||||||
|
|
|
||||||
6
.vscode/extensions.json
vendored
6
.vscode/extensions.json
vendored
|
|
@ -1,6 +0,0 @@
|
||||||
{
|
|
||||||
"recommendations": [
|
|
||||||
"ms-azuretools.vscode-azurefunctions",
|
|
||||||
"ms-python.python"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
12
.vscode/launch.json
vendored
12
.vscode/launch.json
vendored
|
|
@ -1,12 +0,0 @@
|
||||||
{
|
|
||||||
"version": "0.2.0",
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "Attach to Python Functions",
|
|
||||||
"type": "python",
|
|
||||||
"request": "attach",
|
|
||||||
"port": 9091,
|
|
||||||
"preLaunchTask": "func: host start"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
9
.vscode/settings.json
vendored
9
.vscode/settings.json
vendored
|
|
@ -1,8 +1,3 @@
|
||||||
{
|
{
|
||||||
"azureFunctions.deploySubpath": ".",
|
"python.pythonPath": "/usr/local/bin/python3"
|
||||||
"azureFunctions.scmDoBuildDuringDeployment": true,
|
}
|
||||||
"azureFunctions.pythonVenv": ".venv",
|
|
||||||
"azureFunctions.projectLanguage": "Python",
|
|
||||||
"azureFunctions.projectRuntime": "~3",
|
|
||||||
"debug.internalConsoleOptions": "neverOpen"
|
|
||||||
}
|
|
||||||
26
.vscode/tasks.json
vendored
26
.vscode/tasks.json
vendored
|
|
@ -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": []
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
@ -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
|
|
||||||
)
|
|
||||||
|
|
@ -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"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
{
|
|
||||||
"name": "Azure"
|
|
||||||
}
|
|
||||||
|
|
@ -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
|
|
||||||
)
|
|
||||||
|
|
@ -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"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
{
|
|
||||||
"name": "Azure"
|
|
||||||
}
|
|
||||||
|
|
@ -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"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
19
README.md
19
README.md
|
|
@ -1,18 +1 @@
|
||||||
# BotModels
|
This is sample Python Flask application.
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
@ -9,12 +9,22 @@ import json
|
||||||
|
|
||||||
predictor = None
|
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.')
|
logging.info('General Bots QA.')
|
||||||
|
|
||||||
content = req.form.get('content')
|
content = request.form.get('content')
|
||||||
question = req.params.get('question')
|
question = request.args.get('question')
|
||||||
|
key = request.args.get('key')
|
||||||
|
|
||||||
|
if not hmac.compare_digest(key, 'starter'):
|
||||||
|
return 'Invalid key.'
|
||||||
|
|
||||||
global predictor
|
global predictor
|
||||||
if predictor is None:
|
if predictor is None:
|
||||||
predictor = Predictor.from_path("https://storage.googleapis.com/allennlp-public-models/transformer-qa-2020-10-03.tar.gz")
|
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:
|
if answer:
|
||||||
return func.HttpResponse(answer)
|
return answer
|
||||||
else:
|
else:
|
||||||
return func.HttpResponse(
|
return "No answers for this question."
|
||||||
"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
|
if __name__ == '__main__':
|
||||||
)
|
app.run(debug=True)
|
||||||
|
|
||||||
15
host.json
15
host.json
|
|
@ -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)"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,4 +0,0 @@
|
||||||
{
|
|
||||||
"$schema": "http://json.schemastore.org/proxies",
|
|
||||||
"proxies": {}
|
|
||||||
}
|
|
||||||
|
|
@ -8,3 +8,5 @@ numpy
|
||||||
allennlp
|
allennlp
|
||||||
allennlp-models
|
allennlp-models
|
||||||
nltk
|
nltk
|
||||||
|
Flask>=1.0,<=1.1.2
|
||||||
|
hashlib
|
||||||
|
|
|
||||||
14
templates/index.html
Normal file
14
templates/index.html
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<title>Azure Web Apps</title>
|
||||||
|
<link rel="stylesheet" href="css/style.css">
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<h1>Welcome to Azure Web Apps!!</h1>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
Loading…
Add table
Reference in a new issue