mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-12 12:25:20 +00:00
Resolves #19312 Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
parent
22e85df448
commit
485896753d
2 changed files with 21 additions and 22 deletions
|
|
@ -35,6 +35,7 @@ from pydantic import BaseModel
|
||||||
|
|
||||||
|
|
||||||
from open_webui.utils.auth import get_admin_user, get_verified_user
|
from open_webui.utils.auth import get_admin_user, get_verified_user
|
||||||
|
from open_webui.utils.headers import include_user_info_headers
|
||||||
from open_webui.config import (
|
from open_webui.config import (
|
||||||
WHISPER_MODEL_AUTO_UPDATE,
|
WHISPER_MODEL_AUTO_UPDATE,
|
||||||
WHISPER_MODEL_DIR,
|
WHISPER_MODEL_DIR,
|
||||||
|
|
@ -364,23 +365,17 @@ async def speech(request: Request, user=Depends(get_verified_user)):
|
||||||
**(request.app.state.config.TTS_OPENAI_PARAMS or {}),
|
**(request.app.state.config.TTS_OPENAI_PARAMS or {}),
|
||||||
}
|
}
|
||||||
|
|
||||||
r = await session.post(
|
|
||||||
url=f"{request.app.state.config.TTS_OPENAI_API_BASE_URL}/audio/speech",
|
|
||||||
json=payload,
|
|
||||||
headers = {
|
headers = {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"Authorization": f"Bearer {request.app.state.config.TTS_OPENAI_API_KEY}",
|
"Authorization": f"Bearer {request.app.state.config.TTS_OPENAI_API_KEY}",
|
||||||
**(
|
|
||||||
{
|
|
||||||
"X-OpenWebUI-User-Name": quote(user.name, safe=" "),
|
|
||||||
"X-OpenWebUI-User-Id": user.id,
|
|
||||||
"X-OpenWebUI-User-Email": user.email,
|
|
||||||
"X-OpenWebUI-User-Role": user.role,
|
|
||||||
}
|
}
|
||||||
if ENABLE_FORWARD_USER_INFO_HEADERS
|
if ENABLE_FORWARD_USER_INFO_HEADERS:
|
||||||
else {}
|
headers = include_user_info_headers(headers, user)
|
||||||
),
|
|
||||||
},
|
r = await session.post(
|
||||||
|
url=f"{request.app.state.config.TTS_OPENAI_API_BASE_URL}/audio/speech",
|
||||||
|
json=payload,
|
||||||
|
headers=headers,
|
||||||
ssl=AIOHTTP_CLIENT_SESSION_SSL,
|
ssl=AIOHTTP_CLIENT_SESSION_SSL,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -570,7 +565,7 @@ async def speech(request: Request, user=Depends(get_verified_user)):
|
||||||
return FileResponse(file_path)
|
return FileResponse(file_path)
|
||||||
|
|
||||||
|
|
||||||
def transcription_handler(request, file_path, metadata):
|
def transcription_handler(request, file_path, metadata, user=None):
|
||||||
filename = os.path.basename(file_path)
|
filename = os.path.basename(file_path)
|
||||||
file_dir = os.path.dirname(file_path)
|
file_dir = os.path.dirname(file_path)
|
||||||
id = filename.split(".")[0]
|
id = filename.split(".")[0]
|
||||||
|
|
@ -621,11 +616,15 @@ def transcription_handler(request, file_path, metadata):
|
||||||
if language:
|
if language:
|
||||||
payload["language"] = language
|
payload["language"] = language
|
||||||
|
|
||||||
r = requests.post(
|
|
||||||
url=f"{request.app.state.config.STT_OPENAI_API_BASE_URL}/audio/transcriptions",
|
|
||||||
headers = {
|
headers = {
|
||||||
"Authorization": f"Bearer {request.app.state.config.STT_OPENAI_API_KEY}"
|
"Authorization": f"Bearer {request.app.state.config.STT_OPENAI_API_KEY}"
|
||||||
},
|
}
|
||||||
|
if user and ENABLE_FORWARD_USER_INFO_HEADERS:
|
||||||
|
headers = include_user_info_headers(headers, user)
|
||||||
|
|
||||||
|
r = requests.post(
|
||||||
|
url=f"{request.app.state.config.STT_OPENAI_API_BASE_URL}/audio/transcriptions",
|
||||||
|
headers=headers,
|
||||||
files={"file": (filename, open(file_path, "rb"))},
|
files={"file": (filename, open(file_path, "rb"))},
|
||||||
data=payload,
|
data=payload,
|
||||||
)
|
)
|
||||||
|
|
@ -1027,7 +1026,7 @@ def transcription_handler(request, file_path, metadata):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def transcribe(request: Request, file_path: str, metadata: Optional[dict] = None):
|
def transcribe(request: Request, file_path: str, metadata: Optional[dict] = None, user=None):
|
||||||
log.info(f"transcribe: {file_path} {metadata}")
|
log.info(f"transcribe: {file_path} {metadata}")
|
||||||
|
|
||||||
if is_audio_conversion_required(file_path):
|
if is_audio_conversion_required(file_path):
|
||||||
|
|
@ -1054,7 +1053,7 @@ def transcribe(request: Request, file_path: str, metadata: Optional[dict] = None
|
||||||
with ThreadPoolExecutor() as executor:
|
with ThreadPoolExecutor() as executor:
|
||||||
# Submit tasks for each chunk_path
|
# Submit tasks for each chunk_path
|
||||||
futures = [
|
futures = [
|
||||||
executor.submit(transcription_handler, request, chunk_path, metadata)
|
executor.submit(transcription_handler, request, chunk_path, metadata, user)
|
||||||
for chunk_path in chunk_paths
|
for chunk_path in chunk_paths
|
||||||
]
|
]
|
||||||
# Gather results as they complete
|
# Gather results as they complete
|
||||||
|
|
@ -1189,7 +1188,7 @@ def transcription(
|
||||||
if language:
|
if language:
|
||||||
metadata = {"language": language}
|
metadata = {"language": language}
|
||||||
|
|
||||||
result = transcribe(request, file_path, metadata)
|
result = transcribe(request, file_path, metadata, user)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
**result,
|
**result,
|
||||||
|
|
|
||||||
|
|
@ -102,7 +102,7 @@ def process_uploaded_file(request, file, file_path, file_item, file_metadata, us
|
||||||
)
|
)
|
||||||
):
|
):
|
||||||
file_path = Storage.get_file(file_path)
|
file_path = Storage.get_file(file_path)
|
||||||
result = transcribe(request, file_path, file_metadata)
|
result = transcribe(request, file_path, file_metadata, user)
|
||||||
|
|
||||||
process_file(
|
process_file(
|
||||||
request,
|
request,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue