feat(training+controls): interactive video pipeline, training blocks, control generator, CE libraries
Some checks failed
CI/CD / go-lint (push) Has been skipped
CI/CD / python-lint (push) Has been skipped
CI/CD / nodejs-lint (push) Has been skipped
CI/CD / test-go-ai-compliance (push) Failing after 37s
CI/CD / test-python-backend-compliance (push) Successful in 39s
CI/CD / test-python-document-crawler (push) Successful in 26s
CI/CD / test-python-dsms-gateway (push) Successful in 23s
CI/CD / validate-canonical-controls (push) Successful in 12s
CI/CD / Deploy (push) Has been skipped
Some checks failed
CI/CD / go-lint (push) Has been skipped
CI/CD / python-lint (push) Has been skipped
CI/CD / nodejs-lint (push) Has been skipped
CI/CD / test-go-ai-compliance (push) Failing after 37s
CI/CD / test-python-backend-compliance (push) Successful in 39s
CI/CD / test-python-document-crawler (push) Successful in 26s
CI/CD / test-python-dsms-gateway (push) Successful in 23s
CI/CD / validate-canonical-controls (push) Successful in 12s
CI/CD / Deploy (push) Has been skipped
Interactive Training Videos (CP-TRAIN): - DB migration 022: training_checkpoints + checkpoint_progress tables - NarratorScript generation via Anthropic (AI Teacher persona, German) - TTS batch synthesis + interactive video pipeline (slides + checkpoint slides + FFmpeg) - 4 new API endpoints: generate-interactive, interactive-manifest, checkpoint submit, checkpoint progress - InteractiveVideoPlayer component (HTML5 Video, quiz overlay, seek protection, progress tracking) - Learner portal integration with automatic completion on all checkpoints passed - 30 new tests (handler validation + grading logic + manifest/progress + seek protection) Training Blocks: - Block generator, block store, block config CRUD + preview/generate endpoints - Migration 021: training_blocks schema Control Generator + Canonical Library: - Control generator routes + service enhancements - Canonical control library helpers, sidebar entry - Citation backfill service + tests - CE libraries data (hazard, protection, evidence, lifecycle, components) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -70,6 +70,17 @@ class GenerateVideoResponse(BaseModel):
|
||||
size_bytes: int
|
||||
|
||||
|
||||
class PresignedURLRequest(BaseModel):
|
||||
bucket: str
|
||||
object_key: str
|
||||
expires: int = 3600
|
||||
|
||||
|
||||
class PresignedURLResponse(BaseModel):
|
||||
url: str
|
||||
expires_in: int
|
||||
|
||||
|
||||
class VoiceInfo(BaseModel):
|
||||
id: str
|
||||
language: str
|
||||
@@ -105,6 +116,17 @@ async def list_voices():
|
||||
}
|
||||
|
||||
|
||||
@app.post("/presigned-url", response_model=PresignedURLResponse)
|
||||
async def get_presigned_url(req: PresignedURLRequest):
|
||||
"""Generate a presigned URL for accessing a stored media file."""
|
||||
try:
|
||||
url = storage.get_presigned_url(req.bucket, req.object_key, req.expires)
|
||||
return PresignedURLResponse(url=url, expires_in=req.expires)
|
||||
except Exception as e:
|
||||
logger.error(f"Presigned URL generation failed: {e}")
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
|
||||
@app.post("/synthesize", response_model=SynthesizeResponse)
|
||||
async def synthesize(req: SynthesizeRequest):
|
||||
"""Synthesize text to audio and upload to storage."""
|
||||
@@ -132,6 +154,112 @@ async def synthesize(req: SynthesizeRequest):
|
||||
)
|
||||
|
||||
|
||||
class SynthesizeSectionsRequest(BaseModel):
|
||||
sections: list[dict] # [{text, heading}]
|
||||
voice: str = "de_DE-thorsten-high"
|
||||
module_id: str = ""
|
||||
|
||||
|
||||
class SynthesizeSectionsResponse(BaseModel):
|
||||
sections: list[dict]
|
||||
total_duration: float
|
||||
|
||||
|
||||
class GenerateInteractiveVideoRequest(BaseModel):
|
||||
script: dict
|
||||
audio: dict # SynthesizeSectionsResponse
|
||||
module_id: str
|
||||
|
||||
|
||||
class GenerateInteractiveVideoResponse(BaseModel):
|
||||
video_id: str
|
||||
bucket: str
|
||||
object_key: str
|
||||
duration_seconds: float
|
||||
size_bytes: int
|
||||
|
||||
|
||||
@app.post("/synthesize-sections", response_model=SynthesizeSectionsResponse)
|
||||
async def synthesize_sections(req: SynthesizeSectionsRequest):
|
||||
"""Synthesize audio for multiple sections, returning per-section timing."""
|
||||
if not req.sections:
|
||||
raise HTTPException(status_code=400, detail="No sections provided")
|
||||
|
||||
results = []
|
||||
cumulative = 0.0
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
for i, section in enumerate(req.sections):
|
||||
text = section.get("text", "")
|
||||
heading = section.get("heading", f"Section {i+1}")
|
||||
|
||||
if not text.strip():
|
||||
results.append({
|
||||
"heading": heading,
|
||||
"audio_path": "",
|
||||
"audio_object_key": "",
|
||||
"duration": 0.0,
|
||||
"start_timestamp": cumulative,
|
||||
})
|
||||
continue
|
||||
|
||||
try:
|
||||
mp3_path, duration = tts.synthesize_to_mp3(text, tmpdir, suffix=f"_section_{i}")
|
||||
object_key = f"audio/{req.module_id}/section_{i}.mp3"
|
||||
storage.upload_file(AUDIO_BUCKET, object_key, mp3_path, "audio/mpeg")
|
||||
|
||||
results.append({
|
||||
"heading": heading,
|
||||
"audio_path": mp3_path,
|
||||
"audio_object_key": object_key,
|
||||
"duration": round(duration, 2),
|
||||
"start_timestamp": round(cumulative, 2),
|
||||
})
|
||||
cumulative += duration
|
||||
except Exception as e:
|
||||
logger.error(f"Section {i} synthesis failed: {e}")
|
||||
raise HTTPException(status_code=500, detail=f"Section {i} synthesis failed: {e}")
|
||||
|
||||
return SynthesizeSectionsResponse(
|
||||
sections=results,
|
||||
total_duration=round(cumulative, 2),
|
||||
)
|
||||
|
||||
|
||||
@app.post("/generate-interactive-video", response_model=GenerateInteractiveVideoResponse)
|
||||
async def generate_interactive_video(req: GenerateInteractiveVideoRequest):
|
||||
"""Generate an interactive presentation video with checkpoint slides."""
|
||||
try:
|
||||
from video_generator import generate_interactive_presentation_video
|
||||
except ImportError:
|
||||
raise HTTPException(status_code=501, detail="Interactive video generation not available")
|
||||
|
||||
video_id = str(uuid.uuid4())
|
||||
object_key = f"video/{req.module_id}/interactive.mp4"
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
try:
|
||||
mp4_path, duration = generate_interactive_presentation_video(
|
||||
script=req.script,
|
||||
audio_sections=req.audio.get("sections", []),
|
||||
output_dir=tmpdir,
|
||||
storage=storage,
|
||||
audio_bucket=AUDIO_BUCKET,
|
||||
)
|
||||
size_bytes = storage.upload_file(VIDEO_BUCKET, object_key, mp4_path, "video/mp4")
|
||||
except Exception as e:
|
||||
logger.error(f"Interactive video generation failed: {e}")
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
return GenerateInteractiveVideoResponse(
|
||||
video_id=video_id,
|
||||
bucket=VIDEO_BUCKET,
|
||||
object_key=object_key,
|
||||
duration_seconds=round(duration, 2),
|
||||
size_bytes=size_bytes,
|
||||
)
|
||||
|
||||
|
||||
@app.post("/generate-video", response_model=GenerateVideoResponse)
|
||||
async def generate_video(req: GenerateVideoRequest):
|
||||
"""Generate a presentation video from slides + audio."""
|
||||
|
||||
Reference in New Issue
Block a user