47 lines
1.7 KiB
Python
47 lines
1.7 KiB
Python
|
from douzero.evaluation.simulation import evaluate
|
||
|
|
||
|
from douzero.server.orm import Model, Battle, Baseline
|
||
|
from douzero.server.battle import tick
|
||
|
from flask import Flask, jsonify, request
|
||
|
from flask_cors import CORS
|
||
|
from datetime import datetime
|
||
|
from concurrent.futures import ThreadPoolExecutor
|
||
|
|
||
|
app = Flask(__name__)
|
||
|
CORS(app)
|
||
|
|
||
|
Model.create_table()
|
||
|
Battle.create_table()
|
||
|
Baseline.create_table()
|
||
|
positions = ['landlord', 'landlord_up', 'landlord_front', 'landlord_down']
|
||
|
|
||
|
threadpool = ThreadPoolExecutor(1)
|
||
|
|
||
|
@app.route('/upload', methods=['POST'])
|
||
|
def upload():
|
||
|
type = request.form.get('type')
|
||
|
if type not in ['lite_resnet', 'lite_vanilla', 'legacy_vanilla']:
|
||
|
return jsonify({'status': -1, 'message': 'illegal type'})
|
||
|
position = request.form.get("position")
|
||
|
if position not in positions:
|
||
|
return jsonify({'status': -2, 'message': 'illegal position'})
|
||
|
frame = int(request.form.get("frame"))
|
||
|
model_file = request.files.get('model_file')
|
||
|
if model_file is None:
|
||
|
return jsonify({'status': -3, 'message': 'illegal model_file'})
|
||
|
path = "baselines_server/%s_%s_%d.ckpt" % (type, position, frame)
|
||
|
model = Model.get_or_none(Model.path == path)
|
||
|
if model is None:
|
||
|
model_file.save(path)
|
||
|
Model.create(path=path, position=position,type=type,frame=frame,create_time=datetime.now())
|
||
|
Battle.create(challenger_path=path, challenger_position=position, status=0)
|
||
|
threadpool.submit(tick)
|
||
|
return jsonify({'status': 0, 'message': 'success', 'result': ''})
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
import argparse
|
||
|
parser = argparse.ArgumentParser(description='DouZero evaluation backend')
|
||
|
parser.add_argument('--debug', action='store_true')
|
||
|
args = parser.parse_args()
|
||
|
app.run(debug=args.debug, host="0.0.0.0")
|