|
|
@ -8,7 +8,7 @@ from flask import Flask, render_template, request, jsonify |
|
|
from flask_cors import CORS |
|
|
from flask_cors import CORS |
|
|
import sys |
|
|
import sys |
|
|
import warnings |
|
|
import warnings |
|
|
import datetime |
|
|
|
|
|
|
|
|
from datetime import datetime |
|
|
import baostock as bs |
|
|
import baostock as bs |
|
|
import re |
|
|
import re |
|
|
|
|
|
|
|
|
@ -1563,11 +1563,18 @@ def load_model(): |
|
|
|
|
|
|
|
|
model_config = AVAILABLE_MODELS[model_key] |
|
|
model_config = AVAILABLE_MODELS[model_key] |
|
|
|
|
|
|
|
|
print(f"Loading model from: {model_config['model_id']}") |
|
|
|
|
|
|
|
|
print(f"🚀 Loading model from: {model_config['model_id']}") |
|
|
|
|
|
|
|
|
|
|
|
model_path = model_config['model_id'] |
|
|
|
|
|
tokenizer_path = model_config['tokenizer_id'] |
|
|
|
|
|
|
|
|
|
|
|
if os.path.exists(model_path): |
|
|
|
|
|
model_files = os.listdir(model_path) |
|
|
|
|
|
print(f"📄 模型目录中的文件: {model_files}") |
|
|
|
|
|
|
|
|
# 检查模型路径是否存在 |
|
|
# 检查模型路径是否存在 |
|
|
if not os.path.exists(model_config['model_id']): |
|
|
|
|
|
return jsonify({'error': f'Model path does not exist: {model_config["model_id"]}'}), 400 |
|
|
|
|
|
|
|
|
if not os.path.exists(model_path): |
|
|
|
|
|
return jsonify({'error': f'模型路径不存在: {model_path}'}), 400 |
|
|
|
|
|
|
|
|
try: |
|
|
try: |
|
|
# 直接从本地加载模型 |
|
|
# 直接从本地加载模型 |
|
|
@ -1579,10 +1586,14 @@ def load_model(): |
|
|
# 读取模型配置文件获取正确参数 |
|
|
# 读取模型配置文件获取正确参数 |
|
|
config_path = os.path.join(model_config['model_id'], 'config.json') |
|
|
config_path = os.path.join(model_config['model_id'], 'config.json') |
|
|
if os.path.exists(config_path): |
|
|
if os.path.exists(config_path): |
|
|
|
|
|
|
|
|
|
|
|
print(f"读取配置文件: {config_path}") |
|
|
|
|
|
|
|
|
with open(config_path, 'r') as f: |
|
|
with open(config_path, 'r') as f: |
|
|
config = json.load(f) |
|
|
config = json.load(f) |
|
|
|
|
|
|
|
|
print("使用模型配置参数:", config) |
|
|
|
|
|
|
|
|
for key, value in config.items(): |
|
|
|
|
|
print(f" {key}: {value}") |
|
|
|
|
|
|
|
|
# 使用配置中的参数创建tokenizer |
|
|
# 使用配置中的参数创建tokenizer |
|
|
tokenizer = KronosTokenizer( |
|
|
tokenizer = KronosTokenizer( |
|
|
@ -1620,10 +1631,21 @@ def load_model(): |
|
|
return jsonify({ |
|
|
return jsonify({ |
|
|
'success': True, |
|
|
'success': True, |
|
|
'message': f'Model loaded successfully: {model_config["name"]} ({model_config["params"]}) on {device}', |
|
|
'message': f'Model loaded successfully: {model_config["name"]} ({model_config["params"]}) on {device}', |
|
|
'model_info': model_config |
|
|
|
|
|
|
|
|
'model_info': { |
|
|
|
|
|
**model_config, |
|
|
|
|
|
'model_path': model_config['model_id'], |
|
|
|
|
|
'abs_model_path': os.path.abspath(model_config['model_id']), |
|
|
|
|
|
'device': device |
|
|
|
|
|
} |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
except Exception as e: |
|
|
except Exception as e: |
|
|
|
|
|
import traceback |
|
|
|
|
|
print("【API接口错误】") |
|
|
|
|
|
print(f"错误类型: {type(e).__name__}") |
|
|
|
|
|
print(f"错误信息: {str(e)}") |
|
|
|
|
|
traceback.print_exc() |
|
|
|
|
|
print("=" * 60) |
|
|
return jsonify({'error': f'Model loading failed: {str(e)}'}), 500 |
|
|
return jsonify({'error': f'Model loading failed: {str(e)}'}), 500 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -1693,11 +1715,12 @@ def Stock_Data(): |
|
|
'error': f'Login failed: {lg.error_msg}' |
|
|
'error': f'Login failed: {lg.error_msg}' |
|
|
}), 400 |
|
|
}), 400 |
|
|
|
|
|
|
|
|
|
|
|
end_date = datetime.now().strftime('%Y-%m-%d') |
|
|
rs = bs.query_history_k_data_plus( |
|
|
rs = bs.query_history_k_data_plus( |
|
|
stock_code, |
|
|
stock_code, |
|
|
"time,open,high,low,close,volume,amount", |
|
|
"time,open,high,low,close,volume,amount", |
|
|
start_date = '2024-06-01', |
|
|
start_date = '2024-06-01', |
|
|
end_date = '2024-10-31', |
|
|
|
|
|
|
|
|
end_date = end_date, |
|
|
frequency = "5", |
|
|
frequency = "5", |
|
|
adjustflag = "3" |
|
|
adjustflag = "3" |
|
|
) |
|
|
) |
|
|
|