diff --git a/backend/open_webui/routers/audio.py b/backend/open_webui/routers/audio.py index 139b64f7c..01a857a2b 100644 --- a/backend/open_webui/routers/audio.py +++ b/backend/open_webui/routers/audio.py @@ -639,13 +639,14 @@ def transcription_handler(request, file_path, metadata, user=None): 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"))}, - data=payload, - timeout=AIOHTTP_CLIENT_TIMEOUT, - ) + with open(file_path, "rb") as audio_file: + r = requests.post( + url=f"{request.app.state.config.STT_OPENAI_API_BASE_URL}/audio/transcriptions", + headers=headers, + files={"file": (filename, audio_file)}, + data=payload, + timeout=AIOHTTP_CLIENT_TIMEOUT, + ) if r.status_code == 200: # Successful transcription diff --git a/backend/open_webui/routers/pipelines.py b/backend/open_webui/routers/pipelines.py index 20fcd75ee..ebedd3027 100644 --- a/backend/open_webui/routers/pipelines.py +++ b/backend/open_webui/routers/pipelines.py @@ -228,22 +228,23 @@ async def upload_pipeline( headers = {"Authorization": f"Bearer {key}"} async with aiohttp.ClientSession(trust_env=True) as session: - form_data = aiohttp.FormData() - form_data.add_field( - "file", - open(file_path, "rb"), - filename=filename, - content_type="application/octet-stream", - ) + with open(file_path, "rb") as f: + form_data = aiohttp.FormData() + form_data.add_field( + "file", + f, + filename=filename, + content_type="application/octet-stream", + ) - async with session.post( - f"{url}/pipelines/upload", - headers=headers, - data=form_data, - ssl=AIOHTTP_CLIENT_SESSION_SSL, - ) as response: - response.raise_for_status() - data = await response.json() + async with session.post( + f"{url}/pipelines/upload", + headers=headers, + data=form_data, + ssl=AIOHTTP_CLIENT_SESSION_SSL, + ) as response: + response.raise_for_status() + data = await response.json() return {**data} except Exception as e: