Spaces:
Running
Running
Wire diarization spans through MediaProcessor
Browse files
app/services/media_service.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
|
|
|
| 3 |
import os
|
| 4 |
import time
|
| 5 |
from collections.abc import Awaitable, Callable, Sequence
|
|
@@ -106,8 +107,26 @@ class MediaProcessor:
|
|
| 106 |
),
|
| 107 |
temperature=self._float(params.get("temperature"), 0.0, 0.0, 1.0),
|
| 108 |
caption_mode=str(params.get("caption_mode", "segment")),
|
|
|
|
| 109 |
)
|
| 110 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
async def run_ytdlp(self, resolved: ResolvedRequest) -> SuccessResponse:
|
| 112 |
started = time.monotonic()
|
| 113 |
params = resolved.params
|
|
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
| 3 |
+
import json
|
| 4 |
import os
|
| 5 |
import time
|
| 6 |
from collections.abc import Awaitable, Callable, Sequence
|
|
|
|
| 107 |
),
|
| 108 |
temperature=self._float(params.get("temperature"), 0.0, 0.0, 1.0),
|
| 109 |
caption_mode=str(params.get("caption_mode", "segment")),
|
| 110 |
+
diarization=self._diarization(params.get("diarization")),
|
| 111 |
)
|
| 112 |
|
| 113 |
+
@staticmethod
|
| 114 |
+
def _diarization(value: Any) -> list[dict[str, Any]] | None:
|
| 115 |
+
if value is None or value == "":
|
| 116 |
+
return None
|
| 117 |
+
if isinstance(value, str):
|
| 118 |
+
try:
|
| 119 |
+
value = json.loads(value)
|
| 120 |
+
except json.JSONDecodeError as exc:
|
| 121 |
+
from app.core.exceptions import InputError
|
| 122 |
+
|
| 123 |
+
raise InputError("diarization must be valid JSON") from exc
|
| 124 |
+
if not isinstance(value, list):
|
| 125 |
+
from app.core.exceptions import InputError
|
| 126 |
+
|
| 127 |
+
raise InputError("diarization must be a JSON array of speaker spans")
|
| 128 |
+
return value
|
| 129 |
+
|
| 130 |
async def run_ytdlp(self, resolved: ResolvedRequest) -> SuccessResponse:
|
| 131 |
started = time.monotonic()
|
| 132 |
params = resolved.params
|