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
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
David Schwertgen
whisper-asr-webservice
Commits
8683ef47
Commit
8683ef47
authored
1 month ago
by
Subliminal Guy
Browse files
Options
Downloads
Patches
Plain Diff
Add FilePath Handling
Update gitignore and dockerignore
parent
92c59728
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
.dockerignore
+2
-1
2 additions, 1 deletion
.dockerignore
.gitignore
+2
-0
2 additions, 0 deletions
.gitignore
app/webservice.py
+17
-3
17 additions, 3 deletions
app/webservice.py
with
21 additions
and
4 deletions
.dockerignore
+
2
−
1
View file @
8683ef47
.git
.venv
venv
/audio_files
\ No newline at end of file
This diff is collapsed.
Click to expand it.
.gitignore
+
2
−
0
View file @
8683ef47
...
...
@@ -42,3 +42,5 @@ pip-wheel-metadata
poetry/core/*
public
/audio_files
This diff is collapsed.
Click to expand it.
app/webservice.py
+
17
−
3
View file @
8683ef47
import
importlib.metadata
import
os
import
io
from
os
import
path
from
typing
import
Annotated
,
Optional
,
Union
from
urllib.parse
import
quote
...
...
@@ -54,8 +55,9 @@ async def index():
@app.post
(
"
/asr
"
,
tags
=
[
"
Endpoints
"
])
async
def
asr
(
audio_file
:
UploadFile
=
File
(...
)
,
# noqa: B008
file_name
:
str
=
Query
(...,
description
=
"
path to Audio or video file to transcribe
"
),
encode
:
bool
=
Query
(
default
=
True
,
description
=
"
Encode audio first through ffmpeg
"
),
task
:
Union
[
str
,
None
]
=
Query
(
default
=
"
transcribe
"
,
enum
=
[
"
transcribe
"
,
"
translate
"
]),
language
:
Union
[
str
,
None
]
=
Query
(
default
=
None
,
enum
=
LANGUAGE_CODES
),
...
...
@@ -89,9 +91,21 @@ async def asr(
),
output
:
Union
[
str
,
None
]
=
Query
(
default
=
"
txt
"
,
enum
=
[
"
txt
"
,
"
vtt
"
,
"
srt
"
,
"
tsv
"
,
"
json
"
]),
):
print
(
"
filename
"
,
file_name
)
# Get the current working directory
current_directory
=
os
.
getcwd
()
# construct file path
audio_path
=
os
.
path
.
join
(
f
'
{
current_directory
}
/audio_files
'
,
file_name
)
# Print the current working directory
print
(
"
file path
"
,
audio_path
)
# Run transcription in a background thread to keep the event loop responsive
def
_run_transcription
():
audio
=
load_audio
(
audio_file
.
file
,
encode
)
audio
=
load_audio
(
open
(
audio_path
,
'
rb
'
),
encode
)
return
asr_model
.
transcribe
(
audio
,
task
,
...
...
@@ -110,7 +124,7 @@ async def asr(
media_type
=
"
text/plain
"
,
headers
=
{
"
Asr-Engine
"
:
CONFIG
.
ASR_ENGINE
,
"
Content-Disposition
"
:
f
'
attachment; filename=
"
{
quote
(
audio_file
.
filename
)
}
.
{
output
}
"'
,
"
Content-Disposition
"
:
f
'
attachment; filename=
"
{
quote
(
file
_
name
)
}
.
{
output
}
"'
,
},
)
...
...
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