format code
This commit is contained in:
@@ -107,15 +107,16 @@ class JsonResult(TranscriptionInfo):
|
|||||||
segments: list[Segment]
|
segments: list[Segment]
|
||||||
text: str
|
text: str
|
||||||
|
|
||||||
|
|
||||||
def build_json_result(
|
def build_json_result(
|
||||||
generator: Iterable[Segment],
|
generator: Iterable[Segment],
|
||||||
info: TranscriptionInfo,
|
info: TranscriptionInfo,
|
||||||
) -> JsonResult:
|
) -> JsonResult:
|
||||||
segments = [i for i in generator]
|
segments = [i for i in generator]
|
||||||
return JsonResult(
|
return JsonResult(
|
||||||
text="\n".join(i.text for i in segments),
|
text="\n".join(i.text for i in segments),
|
||||||
segments=segments,
|
segments=segments,
|
||||||
**dataclasses.asdict(info)
|
**dataclasses.asdict(info),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -140,6 +141,7 @@ def stream_builder(
|
|||||||
"Detected language '%s' with probability %f"
|
"Detected language '%s' with probability %f"
|
||||||
% (info.language, info.language_probability)
|
% (info.language, info.language_probability)
|
||||||
)
|
)
|
||||||
|
|
||||||
def wrap():
|
def wrap():
|
||||||
for segment in segments:
|
for segment in segments:
|
||||||
if info.language == "zh":
|
if info.language == "zh":
|
||||||
@@ -300,9 +302,9 @@ async def transcription(
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
if not task:
|
if not task:
|
||||||
if request.url.path == '/v1/audio/transcriptions':
|
if request.url.path == "/v1/audio/transcriptions":
|
||||||
task = "transcribe"
|
task = "transcribe"
|
||||||
elif request.url.path == '/v1/audio/translations':
|
elif request.url.path == "/v1/audio/translations":
|
||||||
task = "translate"
|
task = "translate"
|
||||||
else:
|
else:
|
||||||
raise HTTPException(400, "task parameter is required")
|
raise HTTPException(400, "task parameter is required")
|
||||||
|
|||||||
Reference in New Issue
Block a user