mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-20 20:29:06 +00:00
* Self-hosted gpu api * Refactor self-hosted api * Rename model api tests * Use lifespan instead of startup event * Fix self hosted imports * Add newlines * Add response models * Move gpu dir to the root * Add project description * Refactor lifespan * Update env var names for model api tests * Preload diarizarion service * Refactor uploaded file paths
31 lines
874 B
Python
31 lines
874 B
Python
from typing import List
|
|
|
|
from fastapi import APIRouter, Depends, Request
|
|
from pydantic import BaseModel
|
|
|
|
from ..auth import apikey_auth
|
|
from ..services.diarizer import PyannoteDiarizationService
|
|
from ..utils import download_audio_file
|
|
|
|
router = APIRouter(tags=["diarization"])
|
|
|
|
|
|
class DiarizationSegment(BaseModel):
|
|
start: float
|
|
end: float
|
|
speaker: int
|
|
|
|
|
|
class DiarizationResponse(BaseModel):
|
|
diarization: List[DiarizationSegment]
|
|
|
|
|
|
@router.post(
|
|
"/diarize", dependencies=[Depends(apikey_auth)], response_model=DiarizationResponse
|
|
)
|
|
def diarize(request: Request, audio_file_url: str, timestamp: float = 0.0):
|
|
with download_audio_file(audio_file_url) as (file_path, _ext):
|
|
file_path = str(file_path)
|
|
diarizer: PyannoteDiarizationService = request.app.state.diarizer
|
|
return diarizer.diarize_file(file_path, timestamp=timestamp)
|