Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -65,22 +65,14 @@ def get_ip_category(ip_str):
|
|
| 65 |
try:
|
| 66 |
le_action = joblib.load('le_action.pkl')
|
| 67 |
|
| 68 |
-
print("📂 正在
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
if os.path.exists(static_file): base_df = pd.read_csv(static_file)
|
| 77 |
-
elif os.path.exists('baseline_logs (1).csv'): base_df = pd.read_csv('baseline_logs (1).csv')
|
| 78 |
-
else: base_df = pd.DataFrame(columns=["timestamp", "ip_address", "cookie_id", "account", "role", "action", "status"])
|
| 79 |
-
|
| 80 |
-
print("🔄 正在從 Hugging Face 雲端同步最新動態歷史資料...")
|
| 81 |
-
dynamic_df = logger_service.sync_from_hf()
|
| 82 |
-
|
| 83 |
-
baseline_df = pd.concat([base_df, dynamic_df], ignore_index=True) if not dynamic_df.empty else base_df.copy()
|
| 84 |
|
| 85 |
baseline_df['timestamp'] = pd.to_datetime(baseline_df['timestamp'])
|
| 86 |
baseline_df['clean_ip'] = baseline_df['ip_address'].astype(str).apply(lambda x: x.split(" ")[0])
|
|
@@ -360,6 +352,10 @@ def record_log(ip, cookie, account, role, action, status, time_mode, custom_time
|
|
| 360 |
if ai_judgment != "success": status = ai_judgment
|
| 361 |
|
| 362 |
new_log = {"timestamp": log_time, "ip_address": ip, "cookie_id": cookie, "account": account, "role": role, "action": action, "status": status}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 363 |
try: logger_service.push_new_log(new_log)
|
| 364 |
except: pass
|
| 365 |
|
|
|
|
| 65 |
try:
|
| 66 |
le_action = joblib.load('le_action.pkl')
|
| 67 |
|
| 68 |
+
print("📂 正在讀取本地歷史資料庫...")
|
| 69 |
+
# 👉 修改點 1: 直接讀取本地的 baseline_logs.csv,不再向雲端同步
|
| 70 |
+
if os.path.exists('baseline_logs.csv'):
|
| 71 |
+
baseline_df = pd.read_csv('baseline_logs.csv')
|
| 72 |
+
else:
|
| 73 |
+
# 如果檔案不存在,建立帶有標題的空 DataFrame 並存檔
|
| 74 |
+
baseline_df = pd.DataFrame(columns=["timestamp", "ip_address", "cookie_id", "account", "role", "action", "status"])
|
| 75 |
+
baseline_df.to_csv('baseline_logs.csv', index=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
baseline_df['timestamp'] = pd.to_datetime(baseline_df['timestamp'])
|
| 78 |
baseline_df['clean_ip'] = baseline_df['ip_address'].astype(str).apply(lambda x: x.split(" ")[0])
|
|
|
|
| 352 |
if ai_judgment != "success": status = ai_judgment
|
| 353 |
|
| 354 |
new_log = {"timestamp": log_time, "ip_address": ip, "cookie_id": cookie, "account": account, "role": role, "action": action, "status": status}
|
| 355 |
+
|
| 356 |
+
new_df = pd.DataFrame([new_log])
|
| 357 |
+
new_df.to_csv('baseline_logs.csv', mode='a', header=not os.path.exists('baseline_logs.csv'), index=False)
|
| 358 |
+
|
| 359 |
try: logger_service.push_new_log(new_log)
|
| 360 |
except: pass
|
| 361 |
|