當前位置: 首頁>>代碼示例>>Python>>正文


Python flask_restful.marshal_with方法代碼示例

本文整理匯總了Python中flask_restful.marshal_with方法的典型用法代碼示例。如果您正苦於以下問題:Python flask_restful.marshal_with方法的具體用法?Python flask_restful.marshal_with怎麽用?Python flask_restful.marshal_with使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在flask_restful的用法示例。


在下文中一共展示了flask_restful.marshal_with方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: listen_to_web

# 需要導入模塊: import flask_restful [as 別名]
# 或者: from flask_restful import marshal_with [as 別名]
def listen_to_web(args, max_positions, task, process_batch):
    # initialize web app
    app = Flask(__name__, static_folder='')
    api = Api(app)

    # register route for web server

    # a simple form page
    @app.route('/form')
    def form():
        input = request.args.get('input', '')
        inputs = [input]
        results, outputs = process_inputs(args, inputs, max_positions, task, process_batch)
        return render_template('form.html', input=input, outputs=outputs)

    # a dynamic web app with static resource
    @app.route('/')
    def index():
        return render_template('index.html')

    @app.route('/static/<path:path>')
    def send_static(path):
        return send_from_directory('templates/static', path)

    # a JSON api
    resource_fields = {
        'iteration': fields.Integer,
        'src_str': fields.String, 'hypo_str': fields.String,
        'hypo_score': fields.Float, 'pos_scores': fields.Float, 'gleu_scores': fields.Float,
        'fluency_scores': fields.Float, 'alignments': fields.Float,
        'hypo_score_str': fields.String, 'pos_scores_str': fields.String, 'gleu_scores_str': fields.String,
        'fluency_scores_str': fields.String,  'alignments_str': fields.String
    }
    class API(Resource):
        @marshal_with(resource_fields)
        def get(self, input):
            inputs = [input]
            results, outputs = process_inputs(args, inputs, max_positions, task, process_batch)
            # return outputs # raw string outputs
            return results # json

    # register routes for API
    api.add_resource(API, '/api/<string:input>')

    # listen with web server
    print('server running at port: {}'.format(args.port))
    http_server = WSGIServer(('', args.port), app)
    http_server.serve_forever() 
開發者ID:rgcottrell,項目名稱:pytorch-human-performance-gec,代碼行數:50,代碼來源:interactive.py


注:本文中的flask_restful.marshal_with方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。