Last active
October 23, 2020 02:29
-
-
Save binhna/e0d2d8e4be51a2ce79eed0108db1e62f to your computer and use it in GitHub Desktop.
Flask API boilerplate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, request, jsonify | |
from flask_bootstrap import Bootstrap | |
from flask_cors import CORS | |
import torch | |
import pickle | |
from infer_chunking import load_model, infer_sentence | |
task_er, model_er, is_cuda = load_model() | |
app = Flask(__name__) | |
Bootstrap(app) | |
cors = CORS(app, resources={r'/*': {"origins": '*'}}) | |
app.config['CORS_HEADER'] = 'Content-Type' | |
@app.route('/chunking', methods=['POST', 'GET']) | |
def chunking(): | |
if request.method == 'POST': | |
sentence = request.json['sentence'] | |
else: | |
sentence = request.args.get('sentence') | |
output = infer_sentence(sentence, task_er, model_er, is_cuda) | |
return jsonify({"output": output}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from routers import app | |
from argparse import ArgumentParser | |
import os | |
if __name__ == "__main__": | |
# parser = ArgumentParser() | |
# parser.add_argument('--port', default=27070, type=int) | |
# args = parser.parse_args() | |
p = int(os.getenv('PORT', 27071)) | |
app.run(debug=False, host='0.0.0.0', port=p, threaded=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment