From e0b46deb9889d25832fb392307e9fdccb52d3528 Mon Sep 17 00:00:00 2001 From: Talha SARI Date: Sun, 5 May 2024 04:00:56 +0300 Subject: [PATCH] Fix whisper streaming (#733) * change endpoint name to transcribe to match example usage * add remote method to modal function usage * use aio to convert synch map into asynch * minor fix * change sleep to 0, fixed the curl giving error otherwise * correct old typo --------- Co-authored-by: Charles Frye --- 06_gpu_and_ml/openai_whisper/streaming/main.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/06_gpu_and_ml/openai_whisper/streaming/main.py b/06_gpu_and_ml/openai_whisper/streaming/main.py index cc8ae23b3..676d2b485 100644 --- a/06_gpu_and_ml/openai_whisper/streaming/main.py +++ b/06_gpu_and_ml/openai_whisper/streaming/main.py @@ -183,16 +183,16 @@ async def stream_whisper(audio_data: bytes): f.flush() segment_gen = split_silences(f.name) - for result in transcribe_segment.starmap( + async for result in transcribe_segment.starmap( segment_gen, kwargs=dict(audio_data=audio_data, model="base.en") ): - # Must cooperatively yeild here otherwise `StreamingResponse` will not iteratively return stream parts. - # see: https://github.com/python/asyncio/issues/284 - await asyncio.sleep(0.5) + # Must cooperatively yield here otherwise `StreamingResponse` will not iteratively return stream parts. + # see: https://github.com/python/asyncio/issues/284#issuecomment-154162668 + await asyncio.sleep(0) yield result["text"] -@web_app.get("/") +@web_app.get("/transcribe") async def transcribe(url: str): """ Usage: @@ -213,7 +213,7 @@ async def transcribe(url: str): print(f"downloading {url}") try: - audio_data = download_mp3_from_youtube(url) + audio_data = download_mp3_from_youtube.remote(url) except pytube.exceptions.RegexMatchError: raise HTTPException( status_code=422, detail=f"Could not process url {url}"