admin can split a sentence into 2 sentences
This commit is contained in:
@@ -41,7 +41,7 @@ from .models import (
|
||||
VideoUploadResponse,
|
||||
)
|
||||
from .oss import VolcanoOSSUploader
|
||||
from .processing import VideoProcessor
|
||||
from .processing import VideoProcessor, split_sentence_text
|
||||
from .repository import VideoRepository
|
||||
from .store import BoundaryStore
|
||||
from .transcription import MossTranscriber, Transcriber
|
||||
@@ -328,6 +328,41 @@ def create_app(
|
||||
raise HTTPException(status_code=404, detail="Sentence was not found.")
|
||||
return sentence
|
||||
|
||||
@application.put(
|
||||
"/api/v1/admin/videos/{video_hash}/sentences/{sentence_index}/split",
|
||||
response_model=List[SentenceBoundary],
|
||||
dependencies=[Depends(require_admin)],
|
||||
)
|
||||
def split_sentence(
|
||||
payload: SentenceTextUpdate,
|
||||
video_hash: str = SHA256_PATH,
|
||||
sentence_index: int = ApiPath(ge=0),
|
||||
) -> List[SentenceBoundary]:
|
||||
video = video_repository.get_video(video_hash)
|
||||
sentence = video_repository.get_sentence(video_hash, sentence_index)
|
||||
if video is None or sentence is None:
|
||||
raise HTTPException(status_code=404, detail="Sentence was not found.")
|
||||
|
||||
media_path = service_settings.videos_dir / video["stored_filename"]
|
||||
replacements = split_sentence_text(
|
||||
transcriber=moss,
|
||||
media_path=media_path,
|
||||
sentence=sentence,
|
||||
text=payload.text,
|
||||
language=payload.language if payload.language is not None else sentence.language,
|
||||
)
|
||||
try:
|
||||
result = video_repository.replace_sentence(
|
||||
video_hash,
|
||||
sentence_index,
|
||||
replacements,
|
||||
)
|
||||
except ValueError as exc:
|
||||
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
||||
if result is None:
|
||||
raise HTTPException(status_code=404, detail="Sentence was not found.")
|
||||
return result
|
||||
|
||||
@application.delete(
|
||||
"/api/v1/admin/videos/{video_hash}",
|
||||
status_code=204,
|
||||
|
||||
Reference in New Issue
Block a user