Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -62,8 +62,7 @@ def load_champion_models():
|
|
| 62 |
"Hãy đảm bảo 5 file .pkl nằm trong thư mục 'models/'.")
|
| 63 |
return []
|
| 64 |
|
| 65 |
-
@st.
|
| 66 |
-
def load_performance_data(file_path="data/final_5_day_results_df.csv"):
|
| 67 |
"""Tải dữ liệu hiệu suất đã tính toán trước cho Tab 3."""
|
| 68 |
try:
|
| 69 |
df = pd.read_csv(file_path)
|
|
@@ -211,15 +210,17 @@ elif app_section == "Live 5-Day Forecast":
|
|
| 211 |
# Lấy giá trị thực tế để so sánh
|
| 212 |
actual_values = y_test.loc[selected_date_ts].values
|
| 213 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 214 |
for i in range(5):
|
| 215 |
with cols[i]:
|
| 216 |
|
| 217 |
-
# --- SỬA LỖI 1:
|
| 218 |
actual_val = actual_values[i]
|
| 219 |
-
if pd.
|
| 220 |
-
delta_text = "Actual: --"
|
| 221 |
-
else:
|
| 222 |
-
delta_text = f"Actual: {actual_val:.1f}°C"
|
| 223 |
# --- KẾT THÚC SỬA LỖI 1 ---
|
| 224 |
|
| 225 |
st.metric(
|
|
@@ -286,6 +287,39 @@ elif app_section == "Live 5-Day Forecast":
|
|
| 286 |
template="plotly_white", legend=dict(x=0.01, y=0.99)
|
| 287 |
)
|
| 288 |
st.plotly_chart(fig, use_container_width=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 289 |
else:
|
| 290 |
st.warning("Vui lòng đợi... Đang tải dữ liệu hoặc mô hình.")
|
| 291 |
|
|
|
|
| 62 |
"Hãy đảm bảo 5 file .pkl nằm trong thư mục 'models/'.")
|
| 63 |
return []
|
| 64 |
|
| 65 |
+
@st.cache_datadef load_performance_data(file_path="data/final_5_day_results_df.csv"):
|
|
|
|
| 66 |
"""Tải dữ liệu hiệu suất đã tính toán trước cho Tab 3."""
|
| 67 |
try:
|
| 68 |
df = pd.read_csv(file_path)
|
|
|
|
| 210 |
# Lấy giá trị thực tế để so sánh
|
| 211 |
actual_values = y_test.loc[selected_date_ts].values
|
| 212 |
|
| 213 |
+
# --- ÁP DỤNG LOGIC (1) TỪ CODE THAM KHẢO ---
|
| 214 |
+
# Kiểm tra xem có bất kỳ giá trị 'Actual' nào bị thiếu không
|
| 215 |
+
is_partial_forecast = any(pd.isna(v) for v in actual_values)
|
| 216 |
+
# ----------------------------------------------
|
| 217 |
+
|
| 218 |
for i in range(5):
|
| 219 |
with cols[i]:
|
| 220 |
|
| 221 |
+
# --- SỬA LỖI 1 (TINH CHỈNH): Sử dụng logic pd.notna từ code tham khảo ---
|
| 222 |
actual_val = actual_values[i]
|
| 223 |
+
delta_text = f"Actual: {actual_val:.1f}°C" if pd.notna(actual_val) else "Actual: --"
|
|
|
|
|
|
|
|
|
|
| 224 |
# --- KẾT THÚC SỬA LỖI 1 ---
|
| 225 |
|
| 226 |
st.metric(
|
|
|
|
| 287 |
template="plotly_white", legend=dict(x=0.01, y=0.99)
|
| 288 |
)
|
| 289 |
st.plotly_chart(fig, use_container_width=True)
|
| 290 |
+
|
| 291 |
+
|
| 292 |
+
# --- ÁP DỤNG LOGIC (2) TỪ CODE THAM KHẢO ---
|
| 293 |
+
st.subheader("5-Day Forecast vs. Actual Comparison")
|
| 294 |
+
|
| 295 |
+
if is_partial_forecast:
|
| 296 |
+
st.info("Không thể vẽ biểu đồ so sánh Actual vs. Forecast vì "
|
| 297 |
+
"đã chọn ngày quá gần cuối test set (thiếu dữ liệu 'thực tế').")
|
| 298 |
+
else:
|
| 299 |
+
fig_comp = go.Figure()
|
| 300 |
+
|
| 301 |
+
# Add Forecast trace
|
| 302 |
+
fig_comp.add_trace(go.Scatter(
|
| 303 |
+
x=forecast_dates, y=predictions,
|
| 304 |
+
mode='lines+markers', name='5-Day Forecast',
|
| 305 |
+
line=dict(color='red', dash='dot')
|
| 306 |
+
))
|
| 307 |
+
|
| 308 |
+
# Add Actual trace
|
| 309 |
+
fig_comp.add_trace(go.Scatter(
|
| 310 |
+
x=forecast_dates, y=actual_values,
|
| 311 |
+
mode='lines+markers', name='5-Day Actual',
|
| 312 |
+
line=dict(color='blue')
|
| 313 |
+
))
|
| 314 |
+
|
| 315 |
+
fig_comp.update_layout(
|
| 316 |
+
title="5-Day Forecast vs. Actual Values",
|
| 317 |
+
xaxis_title="Date", yaxis_title="Temperature (°C)",
|
| 318 |
+
template="plotly_white", legend=dict(x=0.01, y=0.99)
|
| 319 |
+
)
|
| 320 |
+
st.plotly_chart(fig_comp, use_container_width=True)
|
| 321 |
+
# --- KẾT THÚC ÁP DỤNG LOGIC (2) ---
|
| 322 |
+
|
| 323 |
else:
|
| 324 |
st.warning("Vui lòng đợi... Đang tải dữ liệu hoặc mô hình.")
|
| 325 |
|