From 998239de5ff95124d162aee377b6b6d43d4d2cb5 Mon Sep 17 00:00:00 2001 From: zhaojinghao Date: Mon, 12 Dec 2022 10:37:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9response?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- run.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/run.py b/run.py index 406d76b..dfaf0cd 100644 --- a/run.py +++ b/run.py @@ -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)