Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,6 +14,11 @@ from fastapi import FastAPI
|
|
| 14 |
import uvicorn
|
| 15 |
from huggingface_hub import HfApi, hf_hub_download
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
# 底层特征引擎 (Teacher)
|
| 18 |
from libriichi3p.mjai import Bot as RiichiBot
|
| 19 |
from libriichi3p.consts import ACTION_SPACE
|
|
@@ -346,31 +351,38 @@ def worker_pipeline():
|
|
| 346 |
worker_status["status"] = f"Failed to fetch {URL_LIST_FILE}: {e}"
|
| 347 |
return
|
| 348 |
|
| 349 |
-
headers = {"User-Agent": "Mozilla/5.0"}
|
| 350 |
encoder = FeatureEncoder(chunk_size=2048, pool_size=8)
|
| 351 |
worker_status["status"] = "Mining..."
|
| 352 |
|
| 353 |
for url in target_urls:
|
| 354 |
worker_status["current_target"] = url
|
| 355 |
-
log_match = re.search(r'log=([^&]+)', url)
|
| 356 |
-
tw_match = re.search(r'tw=(\d+)', url)
|
| 357 |
-
if not log_match: continue
|
| 358 |
-
|
| 359 |
-
tw = int(tw_match.group(1)) if tw_match else -1
|
| 360 |
-
log_id = log_match.group(1)
|
| 361 |
|
| 362 |
try:
|
| 363 |
-
|
| 364 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 365 |
|
| 366 |
for game in parsed_games:
|
|
|
|
| 367 |
for j in range(3):
|
| 368 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 369 |
game[0]['id'] = j
|
| 370 |
encoder.process_game(game)
|
| 371 |
|
| 372 |
worker_status["urls_processed"] += 1
|
| 373 |
except Exception as e:
|
|
|
|
|
|
|
| 374 |
worker_status["errors"] += 1
|
| 375 |
|
| 376 |
encoder.save_and_check_upload()
|
|
|
|
| 14 |
import uvicorn
|
| 15 |
from huggingface_hub import HfApi, hf_hub_download
|
| 16 |
|
| 17 |
+
# ==========================================
|
| 18 |
+
# [新增] 导入我们刚刚制作的单文件下载器
|
| 19 |
+
# ==========================================
|
| 20 |
+
from paipu_downloader import download_paipu
|
| 21 |
+
|
| 22 |
# 底层特征引擎 (Teacher)
|
| 23 |
from libriichi3p.mjai import Bot as RiichiBot
|
| 24 |
from libriichi3p.consts import ACTION_SPACE
|
|
|
|
| 351 |
worker_status["status"] = f"Failed to fetch {URL_LIST_FILE}: {e}"
|
| 352 |
return
|
| 353 |
|
|
|
|
| 354 |
encoder = FeatureEncoder(chunk_size=2048, pool_size=8)
|
| 355 |
worker_status["status"] = "Mining..."
|
| 356 |
|
| 357 |
for url in target_urls:
|
| 358 |
worker_status["current_target"] = url
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 359 |
|
| 360 |
try:
|
| 361 |
+
# 1. 使用统一下载接口(支持天凤/雀魂自动识别)
|
| 362 |
+
paipu_json_str = download_paipu(url)
|
| 363 |
+
paipu_data = json.loads(paipu_json_str)
|
| 364 |
+
|
| 365 |
+
# 2. 从解析后的数据中提取目标玩家座位 (0, 1, 2)
|
| 366 |
+
target_seat = paipu_data.get('pov', -1)
|
| 367 |
+
|
| 368 |
+
# 3. 将统一的 JSON 数据喂给解析器
|
| 369 |
+
parsed_games = TenhouParser.parse_log(paipu_data)
|
| 370 |
|
| 371 |
for game in parsed_games:
|
| 372 |
+
# 默认是三麻,遍历3个座位
|
| 373 |
for j in range(3):
|
| 374 |
+
# 如果能解析出固定视角(target_seat != -1),就只处理那个视角的特征,丢弃其他视角的冗余计算
|
| 375 |
+
if target_seat != -1 and j != target_seat:
|
| 376 |
+
continue
|
| 377 |
+
|
| 378 |
+
# 动态注入当前处理的视角ID
|
| 379 |
game[0]['id'] = j
|
| 380 |
encoder.process_game(game)
|
| 381 |
|
| 382 |
worker_status["urls_processed"] += 1
|
| 383 |
except Exception as e:
|
| 384 |
+
print(f"Error processing {url}: {e}")
|
| 385 |
+
traceback.print_exc()
|
| 386 |
worker_status["errors"] += 1
|
| 387 |
|
| 388 |
encoder.save_and_check_upload()
|