repaire sentences

This commit is contained in:
2026-10-21 19:39:04 +08:00
parent 176d722c77
commit 532d9900ba
13 changed files with 1233 additions and 60 deletions

View File

@@ -43,6 +43,8 @@ from .models import (
CourseSummary,
CourseTitleUpdate,
SentenceBoundaryAdjust,
SentenceGapRepairRequest,
SentenceGapRepairResponse,
SentenceBoundary,
SentenceBoundaryDocument,
SentenceExplanationRequest,
@@ -688,6 +690,34 @@ def create_app(
background_tasks.add_task(_process_safely, processor, video_hash)
return {"video_hash": video_hash.lower(), "status": "processing_queued"}
@application.post(
"/api/v1/admin/videos/{video_hash}/repair-gaps",
response_model=SentenceGapRepairResponse,
dependencies=[Depends(require_admin)],
)
async def repair_sentence_gaps(
payload: Optional[SentenceGapRepairRequest] = None,
video_hash: str = SHA256_PATH,
) -> SentenceGapRepairResponse:
request = payload or SentenceGapRepairRequest()
try:
result = await run_in_threadpool(
processor.repair_gaps,
video_hash,
request.min_gap_ms,
)
except KeyError:
raise HTTPException(status_code=404, detail="Video was not found.") from None
except FileNotFoundError as exc:
raise HTTPException(status_code=404, detail=str(exc)) from exc
except ValueError as exc:
raise HTTPException(status_code=400, detail=str(exc)) from exc
except RuntimeError as exc:
raise HTTPException(status_code=503, detail=str(exc)) from exc
if result["inserted_count"]:
application.state.subtitle_translations.start_missing(video_hash)
return SentenceGapRepairResponse(video_hash=video_hash.lower(), **result)
@application.get(
"/api/v1/admin/videos/{video_hash}/subtitle-translation",
response_model=AdminSubtitleTranslationResponse,