fiewolf1000 commited on
Commit
fb0f54f
·
verified ·
1 Parent(s): 57220a4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -7
app.py CHANGED
@@ -76,19 +76,27 @@ predictor = load_model()
76
  initialize_html_template()
77
 
78
  @app.route("/")
 
79
  def index():
80
  # 获取当前业务日
81
  current_business_date, _ = get_business_info()
82
- # 仅当业务日变化时,才执行 main_task
83
- #if Config["LAST_INFERENCED_BUSINESS_DATE"] != current_business_date:
 
 
 
84
  main_task(predictor)
85
 
86
  # 读取并返回 HTML
87
- with open(Config["HTML_PATH"], 'r', encoding='utf-8') as f:
88
- html_content = f.read()
89
- return render_template_string(html_content)
90
-
91
-
 
 
 
 
92
 
93
 
94
  @app.route("/prediction_chart.png")
 
76
  initialize_html_template()
77
 
78
  @app.route("/")
79
+
80
  def index():
81
  # 获取当前业务日
82
  current_business_date, _ = get_business_info()
83
+
84
+ # 容错处理:检查配置键是否存在,不存在则执行主任务
85
+ # 同时处理键存在但值为None的情况(首次运行)
86
+ if ("LAST_INFERENCED_BUSINESS_DATE" not in Config
87
+ or Config["LAST_INFERENCED_BUSINESS_DATE"] != current_business_date):
88
  main_task(predictor)
89
 
90
  # 读取并返回 HTML
91
+ try:
92
+ with open(Config["HTML_PATH"], 'r', encoding='utf-8') as f:
93
+ html_content = f.read()
94
+ return render_template_string(html_content)
95
+ except FileNotFoundError:
96
+ # 处理HTML文件不存在的情况
97
+ return "预测页面生成中,请稍后刷新", 202
98
+ except Exception as e:
99
+ return f"页面加载错误:{str(e)}", 500
100
 
101
 
102
  @app.route("/prediction_chart.png")