Skip to content

Commit

Permalink
Fix whisper streaming (#733)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
SeeknnDestroy and charlesfrye committed May 5, 2024
1 parent 5923bff commit e0b46de
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions 06_gpu_and_ml/openai_whisper/streaming/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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}"
Expand Down

0 comments on commit e0b46de

Please sign in to comment.