修改response

This commit is contained in:
zhaojinghao 2022-12-12 10:37:51 +08:00
parent 859a3e2688
commit 998239de5f
1 changed files with 16 additions and 12 deletions

28
run.py
View File

@ -55,22 +55,26 @@ def predict_price():
train_data = None
else:
train_data = pd.read_csv(train_data)
if test_data is None or pd.read_csv(test_data).shape[0] == 0:
if test_data is None:
resp_info["msg"] = "测试数据为空"
resp_info["code"] = 406
else:
test_data = pd.read_csv(test_data)
try:
if train_data is None:
rst = run_boston_price(test_data, None, num_boost_round, early_stopping_rounds, **params)
else:
rst = run_boston_price(test_data, train_data, num_boost_round, early_stopping_rounds, **params)
except Exception as e:
logger.error(f"Error: {e}")
resp_info["msg"] = str(e)
if test_data.shape[0] == 0:
resp_info["msg"] = "测试数据为空"
resp_info["code"] = 406
else:
resp_info["code"] = 200
try:
if train_data is None:
rst = run_boston_price(test_data, None, num_boost_round, early_stopping_rounds, **params)
else:
rst = run_boston_price(test_data, train_data, num_boost_round, early_stopping_rounds, **params)
except Exception as e:
logger.error(f"Error: {e}")
resp_info["msg"] = str(e)
resp_info["code"] = 406
else:
resp_info["code"] = 200
if resp_info["code"] == 200:
resp = make_response(stream_with_context(generate(rst)))
resp.headers["Content-Disposition"] = "attachment; filename=house_price.csv"
@ -119,7 +123,7 @@ def predict_height():
resp_info["code"] = 406
else:
resp_info["code"] = 200
resp_info["data"] = rst
resp_info["data"] = str(rst)
resp_info["dtype"] = TEXT
resp = make_response(json.dumps(resp_info))
resp.status_code = 200
@ -159,4 +163,4 @@ def run_ts_predict():
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8901, debug=False)
app.run(host='0.0.0.0', port=8908, debug=True)