feat: 配置写死与 baked 模块,Alembic 建表,百度仅 BAIDU_*

- 新增 app/baked/algorithm|pipeline,非部署参数不再走 env;Settings 保留 DB/HTTP/RTSP/海康/百度/MinIO/Demo
- 移除 init_db_schema 与 reload 配置;main 仅 check_database;start*.sh 在 uvicorn 前执行 alembic upgrade head
- 依赖 psycopg[binary] 供 Alembic 同步 URL;alembic/env 注释与预发清单更新
- 撕段门控消费管线、各视频/语音/归档调用改为 baked
- 百度环境变量仅 BAIDU_APP_ID、BAIDU_API_KEY、BAIDU_SECRET_KEY 与 BAIDU_* 超时/ASR;人脸脚本与 baidu_speech 文案同步
- 全量单测与 .env.example 更新;.gitignore 忽略 refs/(本地权重/视频不入库)

Made-with: Cursor
This commit is contained in:
Kevin
2026-04-24 15:33:22 +08:00
parent b651364877
commit 8a4bad99d3
47 changed files with 1333 additions and 648 deletions

View File

@@ -14,7 +14,7 @@ from __future__ import annotations
from loguru import logger
from app.config import Settings
from app.baked import pipeline as bp
from app.services.consumable_vision_algorithm import (
PredictionCandidate,
PredictionResult,
@@ -54,10 +54,8 @@ class VisionClassificationHandler:
def __init__(
self,
*,
settings: Settings,
registry: SurgerySessionRegistry,
) -> None:
self._s = settings
self._registry = registry
def _append_vision_consumption_window_if_ready(
@@ -72,8 +70,8 @@ class VisionClassificationHandler:
or not surgery_id
or not camera_id
or (
not self._s.consumption_tsv_log_enabled
and not self._s.consumption_log_markdown_terminal
not bp.CONSUMPTION_TSV_LOG_ENABLED
and not bp.CONSUMPTION_LOG_MARKDOWN_TERMINAL
)
):
return
@@ -81,7 +79,7 @@ class VisionClassificationHandler:
surgery_id=surgery_id,
name_to_code=state.name_to_code,
best=ready.best,
doctor_id=self._s.video_result_doctor_id,
doctor_id=bp.VIDEO_RESULT_DOCTOR_ID,
camera_id=camera_id,
wall_start_epoch=ready.wall_lo,
wall_end_epoch=ready.wall_hi,
@@ -100,7 +98,7 @@ class VisionClassificationHandler:
label = (cls_res.label or "").strip()
t1_pid = (ready.best.t1_pid if ready is not None else "")
item_id = resolve_consumption_item_id(label, t1_pid, state.name_to_code)
voice_floor = self._s.video_voice_confirm_min_confidence
voice_floor = bp.VIDEO_VOICE_CONFIRM_MIN_CONFIDENCE
if conf < voice_floor:
return
@@ -110,7 +108,7 @@ class VisionClassificationHandler:
cand_set = set(cand_order)
ranked = rank_topk_for_candidates(cls_res.topk, cand_order)
auto_th = self._s.video_auto_confirm_confidence
auto_th = bp.VIDEO_AUTO_CONFIRM_CONFIDENCE
def in_allowed(name: str) -> bool:
return name in cand_set
@@ -123,13 +121,13 @@ class VisionClassificationHandler:
state=state,
item_id=item_id or "unknown",
item_name=label or "unknown",
doctor_id=self._s.video_result_doctor_id,
doctor_id=bp.VIDEO_RESULT_DOCTOR_ID,
source="vision",
)
return
if conf >= auto_th and not in_allowed(label):
if ranked and self._s.voice_confirmation_enabled:
if ranked and bp.VOICE_CONFIRMATION_ENABLED:
await self._enqueue(
state,
ranked,
@@ -141,7 +139,7 @@ class VisionClassificationHandler:
)
return
if not self._s.voice_confirmation_enabled:
if not bp.VOICE_CONFIRMATION_ENABLED:
return
if ranked:
@@ -190,22 +188,22 @@ class VisionClassificationHandler:
top_key,
)
if ready is not None and surgery_id and camera_id and (
self._s.consumption_tsv_log_enabled
or self._s.consumption_log_markdown_terminal
bp.CONSUMPTION_TSV_LOG_ENABLED
or bp.CONSUMPTION_LOG_MARKDOWN_TERMINAL
):
append_consumption_pending_window(
surgery_id=surgery_id,
confirmation_id=cid,
model_snap=ready.best,
doctor_id=self._s.video_result_doctor_id,
doctor_id=bp.VIDEO_RESULT_DOCTOR_ID,
camera_id=camera_id,
wall_start_epoch=ready.wall_lo,
wall_end_epoch=ready.wall_hi,
tsv_enabled=self._s.consumption_tsv_log_enabled,
markdown_terminal=self._s.consumption_log_markdown_terminal,
tsv_enabled=bp.CONSUMPTION_TSV_LOG_ENABLED,
markdown_terminal=bp.CONSUMPTION_LOG_MARKDOWN_TERMINAL,
)
await self._registry.append_pending_consumption_detail(
state=state,
confirmation_id=cid,
doctor_id=self._s.video_result_doctor_id,
doctor_id=bp.VIDEO_RESULT_DOCTOR_ID,
)