This commit is contained in:
aenchakattu 2019-02-11 15:05:51 -08:00
Родитель 8ee76f0f71
Коммит 19e79ec96e
2 изменённых файлов: 16 добавлений и 2 удалений

Просмотреть файл

@ -6,6 +6,8 @@ COPY ./blob_mount.json /app/fuse/blob_mount.json
RUN apt-get update && apt-get upgrade -y RUN apt-get update && apt-get upgrade -y
RUN apt-get install -y libgl1-mesa-glx RUN apt-get install -y libgl1-mesa-glx
RUN /usr/local/envs/ai4e_py_api/bin/pip install flask-cors
RUN /usr/local/envs/ai4e_py_api/bin/pip install rasterio==1.0.12 RUN /usr/local/envs/ai4e_py_api/bin/pip install rasterio==1.0.12
# Example of installing additonal Anaconda packages - numpy and pandas # Example of installing additonal Anaconda packages - numpy and pandas

Просмотреть файл

@ -5,6 +5,7 @@
from task_management.api_task import ApiTaskManager from task_management.api_task import ApiTaskManager
from flask import Flask, request from flask import Flask, request
from flask_restful import Resource, Api from flask_restful import Resource, Api
from flask_cors import CORS, cross_origin
from time import sleep from time import sleep
import json import json
from ai4e_app_insights import AppInsights from ai4e_app_insights import AppInsights
@ -34,6 +35,9 @@ print("Creating Application")
api_prefix = getenv('API_PREFIX') api_prefix = getenv('API_PREFIX')
app = Flask(__name__) app = Flask(__name__)
api = Api(app) api = Api(app)
#cors = CORS(app)
app.config['JSON_SORT_KEYS'] = False
# Log requests, traces and exceptions to the Application Insights service # Log requests, traces and exceptions to the Application Insights service
appinsights = AppInsights(app) appinsights = AppInsights(app)
@ -50,18 +54,26 @@ ai4e_wrapper = AI4EWrapper(app)
#load the precomputed results #load the precomputed results
model = ServerModelsCached.run model = ServerModelsCached.run
@app.after_request
def enable_cors(response):
response.headers['Access-Control-Allow-Origin'] = '*'
response.headers['Access-Control-Allow-Methods'] = 'PUT, GET, POST, DELETE, OPTIONS'
response.headers['Access-Control-Allow-Headers'] = 'Origin, Accept, Content-Type, X-Requested-With, X-CSRF-Token'
return response
@app.route('/', methods=['GET']) @app.route('/', methods=['GET'])
def health_check(): def health_check():
return "Health check OK" return "Health check OK"
@app.route(api_prefix + '/predpatch', methods=['POST']) @app.route(api_prefix + '/predPatch', methods=['POST'])
def post(): def post():
# wrap_sync_endpoint wraps your function within a logging trace. # wrap_sync_endpoint wraps your function within a logging trace.
post_data = request.get_json() post_data = request.get_json()
return ai4e_wrapper.wrap_sync_endpoint(pred_patch, "post:pred_patch", data=post_data) return ai4e_wrapper.wrap_sync_endpoint(pred_patch, "post:pred_patch", data=post_data)
@app.route(api_prefix + '/getinput', methods=['GET']) @app.route(api_prefix + '/getInput', methods=['GET'])
def get(): def get():
post_data = json.loads(request.data) post_data = json.loads(request.data)
#return(get_input(post_data)) #return(get_input(post_data))