Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
whisper-asr-webservice
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
David Schwertgen
whisper-asr-webservice
Commits
6f84597d
Commit
6f84597d
authored
2 months ago
by
Subliminal Guy
Browse files
Options
Downloads
Patches
Plain Diff
Make Transcription async so that Status Route stays accesible
parent
e38082e9
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/webservice.py
+17
-10
17 additions, 10 deletions
app/webservice.py
with
17 additions
and
10 deletions
app/webservice.py
+
17
−
10
View file @
6f84597d
...
...
@@ -11,6 +11,7 @@ from fastapi.openapi.docs import get_swagger_ui_html
from
fastapi.responses
import
RedirectResponse
,
StreamingResponse
from
fastapi.staticfiles
import
StaticFiles
from
whisper
import
tokenizer
import
asyncio
from
app.config
import
CONFIG
from
app.factory.asr_model_factory
import
ASRModelFactory
...
...
@@ -88,8 +89,11 @@ async def asr(
),
output
:
Union
[
str
,
None
]
=
Query
(
default
=
"
txt
"
,
enum
=
[
"
txt
"
,
"
vtt
"
,
"
srt
"
,
"
tsv
"
,
"
json
"
]),
):
result
=
asr_model
.
transcribe
(
load_audio
(
audio_file
.
file
,
encode
),
# Run transcription in a background thread to keep the event loop responsive
def
_run_transcription
():
audio
=
load_audio
(
audio_file
.
file
,
encode
)
return
asr_model
.
transcribe
(
audio
,
task
,
language
,
initial_prompt
,
...
...
@@ -98,6 +102,9 @@ async def asr(
{
"
diarize
"
:
diarize
,
"
min_speakers
"
:
min_speakers
,
"
max_speakers
"
:
max_speakers
},
output
,
)
# offload blocking transcription to a thread
result
=
await
asyncio
.
to_thread
(
_run_transcription
)
# stream the transcription result back to the client
return
StreamingResponse
(
result
,
media_type
=
"
text/plain
"
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment