32 lines
897 B
Python
32 lines
897 B
Python
from __future__ import annotations
|
|
|
|
import httpx
|
|
|
|
from cpv3.infrastructure.settings import get_settings
|
|
from cpv3.modules.transcription.schemas import Document
|
|
|
|
|
|
async def generate_captions(
|
|
*, video_s3_path: str, folder: str, transcription: Document
|
|
) -> str:
|
|
"""Generate captions for a video using the Remotion service."""
|
|
settings = get_settings()
|
|
|
|
payload = {
|
|
"folder": folder,
|
|
"videoSrc": video_s3_path,
|
|
"transcription": transcription.model_dump(),
|
|
}
|
|
|
|
async with httpx.AsyncClient(timeout=300) as client:
|
|
resp = await client.post(
|
|
f"{settings.remotion_service_url}/api/render", json=payload
|
|
)
|
|
resp.raise_for_status()
|
|
data = resp.json()
|
|
|
|
if not isinstance(data, dict) or "output" not in data:
|
|
raise RuntimeError("Unexpected response from remotion service")
|
|
|
|
return str(data["output"])
|