Spaces:
Running
Running
Update apis/chat_api.py
Browse files- apis/chat_api.py +11 -4
apis/chat_api.py
CHANGED
@@ -348,11 +348,18 @@ async def whisper_transcribe(
|
|
348 |
)
|
349 |
time_start = time.time()
|
350 |
pipe.model.config.forced_decoder_ids = pipe.tokenizer.get_decoder_prompt_ids(language=language, task="transcribe")
|
351 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
352 |
# rv = data.encode('utf-8')
|
353 |
-
rv = base64.b64encode(file_data).decode()
|
354 |
-
print(rv, "rvrvrvrvr")
|
355 |
-
text = pipe(
|
356 |
time_end = time.time()
|
357 |
item_response["status"] = 200
|
358 |
item_response["result"] = text
|
|
|
348 |
)
|
349 |
time_start = time.time()
|
350 |
pipe.model.config.forced_decoder_ids = pipe.tokenizer.get_decoder_prompt_ids(language=language, task="transcribe")
|
351 |
+
try:
|
352 |
+
suffix = Path(audio_file.filename).suffix
|
353 |
+
with NamedTemporaryFile(delete=False, suffix=suffix) as tmp:
|
354 |
+
shutil.copyfileobj(audio_file.file, tmp)
|
355 |
+
tmp_path = Path(tmp.name)
|
356 |
+
finally:
|
357 |
+
audio_file.file.close()
|
358 |
+
#file_data = await audio_file.read()
|
359 |
# rv = data.encode('utf-8')
|
360 |
+
#rv = base64.b64encode(file_data).decode()
|
361 |
+
#print(rv, "rvrvrvrvr")
|
362 |
+
text = pipe(tmp_path)["text"]
|
363 |
time_end = time.time()
|
364 |
item_response["status"] = 200
|
365 |
item_response["result"] = text
|