#!/usr/bin/env python
# coding=utf-8

# import module
# Load existing model

from flask import Flask, jsonify, request, abort, make_response

app =  Flask(__name__)

@app.route('/tagger/v1.0/model', methods=['GET'])
def get_model():
    return jsonify({'models': "default"})

@app.route('/tagger/v1.0/submit', methods=['POST'])
def create_task():
    if not request.json or not 'content' in request.json:
        abort(400)
    task = {
        'content': request.json['content']
    }
    return jsonify({'labeled': __runModel(task['content'].decode('utf-8'))})

def __runModel(input=""):
        pass
        return output

if __name__ == '__main__':
    app.run(debug=True)

测试

1 curl

curl -i -H "Content-Type: application/json" -X POST -d '{"content": "中国在亚洲"}' http://localhost:5000/tagger/v1.0/submit

2 python3

import requests
url = "http://localhost/tagger/v1.0/submit"
data = "{\"content\":\"中国在亚洲\"}"
data = data.encode('utf-8')
headers = {
    'content-type': "application/json",
    'cache-control': "no-cache",
}
response=requests.request("POST",url,data=data,headers=headers)
print(response.text)
Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐