Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
e516374d
Commit
e516374d
authored
Jun 07, 2024
by
Timothy J. Baek
Browse files
feat: external stt
parent
55dc6c1b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
28 deletions
+62
-28
backend/apps/audio/main.py
backend/apps/audio/main.py
+62
-28
No files found.
backend/apps/audio/main.py
View file @
e516374d
...
@@ -240,6 +240,7 @@ def transcribe(
...
@@ -240,6 +240,7 @@ def transcribe(
f
.
write
(
contents
)
f
.
write
(
contents
)
f
.
close
()
f
.
close
()
if
app
.
state
.
config
.
STT_ENGINE
==
""
:
whisper_kwargs
=
{
whisper_kwargs
=
{
"model_size_or_path"
:
WHISPER_MODEL
,
"model_size_or_path"
:
WHISPER_MODEL
,
"device"
:
whisper_device_type
,
"device"
:
whisper_device_type
,
...
@@ -274,6 +275,39 @@ def transcribe(
...
@@ -274,6 +275,39 @@ def transcribe(
return
{
"text"
:
transcript
.
strip
()}
return
{
"text"
:
transcript
.
strip
()}
elif
app
.
state
.
config
.
STT_ENGINE
==
"openai"
:
headers
=
{
"Authorization"
:
f
"Bearer
{
app
.
state
.
config
.
STT_OPENAI_API_KEY
}
"
}
files
=
{
"file"
:
(
filename
,
open
(
file_path
,
"rb"
))}
data
=
{
"model"
:
"whisper-1"
}
r
=
None
try
:
r
=
requests
.
post
(
url
=
f
"
{
app
.
state
.
config
.
STT_OPENAI_API_BASE_URL
}
/audio/transcriptions"
,
headers
=
headers
,
files
=
files
,
data
=
data
,
)
r
.
raise_for_status
()
return
r
.
json
()
except
Exception
as
e
:
log
.
exception
(
e
)
error_detail
=
"Open WebUI: Server Connection Error"
if
r
is
not
None
:
try
:
res
=
r
.
json
()
if
"error"
in
res
:
error_detail
=
f
"External:
{
res
[
'error'
][
'message'
]
}
"
except
:
error_detail
=
f
"External:
{
e
}
"
raise
HTTPException
(
status_code
=
r
.
status_code
if
r
!=
None
else
500
,
detail
=
error_detail
,
)
except
Exception
as
e
:
except
Exception
as
e
:
log
.
exception
(
e
)
log
.
exception
(
e
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment