From b335d210ee5b9aaa0cd9c4afcbe066a40b53f3f1 Mon Sep 17 00:00:00 2001 From: ppraneth Date: Fri, 5 Dec 2025 13:25:42 +0530 Subject: [PATCH 1/2] fix --- python/sglang/srt/utils/common.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/python/sglang/srt/utils/common.py b/python/sglang/srt/utils/common.py index 08a13f604f8..0619d63e414 100644 --- a/python/sglang/srt/utils/common.py +++ b/python/sglang/srt/utils/common.py @@ -71,7 +71,7 @@ TypeVar, Union, ) -from urllib.parse import urlparse +from urllib.parse import unquote, urlparse import numpy as np import orjson @@ -874,6 +874,9 @@ def load_image( image.load() # Force loading to avoid issues after closing the stream finally: response.close() + elif image_file.startswith("file://"): + image_file = unquote(urlparse(image_file).path) + image = Image.open(image_file) elif image_file.lower().endswith(("png", "jpg", "jpeg", "webp", "gif")): image = Image.open(image_file) elif image_file.startswith("data:"): @@ -894,6 +897,10 @@ def get_image_bytes(image_file: Union[str, bytes]): timeout = int(os.getenv("REQUEST_TIMEOUT", "3")) response = requests.get(image_file, timeout=timeout) return response.content + elif image_file.startswith("file://"): + image_file = unquote(urlparse(image_file).path) + with open(image_file, "rb") as f: + return f.read() elif image_file.lower().endswith(("png", "jpg", "jpeg", "webp", "gif")): with open(image_file, "rb") as f: return f.read() @@ -943,8 +950,11 @@ def load_video(video_file: Union[str, bytes], use_gpu: bool = True): tmp_file.write(video_bytes) tmp_file.close() vr = VideoReader(tmp_file.name, ctx=ctx) + elif video_file.startswith("file://"): + video_file = unquote(urlparse(video_file).path) + vr = VideoReader(video_file, ctx=ctx) # `urlparse` supports file:// paths, and so does VideoReader - elif os.path.isfile(urlparse(video_file).path): + elif os.path.isfile(unquote(urlparse(video_file).path)): vr = VideoReader(video_file, ctx=ctx) else: video_bytes = pybase64.b64decode(video_file, validate=True) From 92c78891fb5f3e653aaf0ab37af03c3f68199d9e Mon Sep 17 00:00:00 2001 From: ppraneth Date: Mon, 8 Dec 2025 18:11:20 +0530 Subject: [PATCH 2/2] add file:// to audio --- python/sglang/srt/utils/common.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/python/sglang/srt/utils/common.py b/python/sglang/srt/utils/common.py index 5ac1d255fec..964f3364647 100644 --- a/python/sglang/srt/utils/common.py +++ b/python/sglang/srt/utils/common.py @@ -830,6 +830,9 @@ def load_audio( audio_file = BytesIO(response.content) response.close() audio, original_sr = sf.read(audio_file) + elif audio_file.startswith("file://"): + audio_file = unquote(urlparse(audio_file).path) + audio, original_sr = sf.read(audio_file) elif isinstance(audio_file, str): audio, original_sr = sf.read(audio_file) else: