Spaces:
Sleeping
Sleeping
fix bug from log display
Browse files
app.py
CHANGED
|
@@ -66,6 +66,11 @@ try:
|
|
| 66 |
|
| 67 |
log_history = baseline_df.sort_values(by='timestamp', ascending=False).head(20).to_dict('records')
|
| 68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
initial_abnormal_logs = [log for log in log_history if "異常" in str(log.get("status", ""))]
|
| 70 |
if initial_abnormal_logs:
|
| 71 |
initial_df_abn = pd.DataFrame(initial_abnormal_logs)
|
|
@@ -469,7 +474,13 @@ with gr.Blocks(title="模擬校園入口與資安防護系統") as demo:
|
|
| 469 |
custom_time_input = gr.Textbox(label="輸入自訂時間", placeholder="格式: YYYY-MM-DD HH:MM:SS", value="2026-03-17 03:00:00", visible=False)
|
| 470 |
gr.Markdown("---")
|
| 471 |
gr.Markdown("### 📊 即時 Log 與 AI 判定區")
|
| 472 |
-
log_display = gr.Dataframe(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 473 |
|
| 474 |
with gr.Column(scale=2):
|
| 475 |
|
|
|
|
| 66 |
|
| 67 |
log_history = baseline_df.sort_values(by='timestamp', ascending=False).head(20).to_dict('records')
|
| 68 |
|
| 69 |
+
# 🌟 修正:先將時間欄位強制轉換為純字串,再轉成字典,避免前端 JS 解析崩潰
|
| 70 |
+
display_df = baseline_df.sort_values(by='timestamp', ascending=False).head(20).copy()
|
| 71 |
+
display_df['timestamp'] = display_df['timestamp'].dt.strftime('%Y-%m-%d %H:%M:%S')
|
| 72 |
+
log_history = display_df.to_dict('records')
|
| 73 |
+
|
| 74 |
initial_abnormal_logs = [log for log in log_history if "異常" in str(log.get("status", ""))]
|
| 75 |
if initial_abnormal_logs:
|
| 76 |
initial_df_abn = pd.DataFrame(initial_abnormal_logs)
|
|
|
|
| 474 |
custom_time_input = gr.Textbox(label="輸入自訂時間", placeholder="格式: YYYY-MM-DD HH:MM:SS", value="2026-03-17 03:00:00", visible=False)
|
| 475 |
gr.Markdown("---")
|
| 476 |
gr.Markdown("### 📊 即時 Log 與 AI 判定區")
|
| 477 |
+
log_display = gr.Dataframe(
|
| 478 |
+
value=pd.DataFrame(log_history) if log_history else None,
|
| 479 |
+
headers=["timestamp", "ip_address", "cookie_id", "account", "role", "action", "status"],
|
| 480 |
+
datatype=["str", "str", "str", "str", "str", "str", "str"],
|
| 481 |
+
interactive=False,
|
| 482 |
+
wrap=True
|
| 483 |
+
)
|
| 484 |
|
| 485 |
with gr.Column(scale=2):
|
| 486 |
|