Commit a89ac72c authored by zhuwenwen's avatar zhuwenwen
Browse files

support multi image input of local files

parent 04d33670
......@@ -6,6 +6,7 @@ from typing import Any, List, Optional, Tuple, TypeVar, Union
import numpy as np
import numpy.typing as npt
from PIL import Image
import os
from vllm.connections import global_http_connection
from vllm.envs import VLLM_AUDIO_FETCH_TIMEOUT, VLLM_IMAGE_FETCH_TIMEOUT
......@@ -30,6 +31,10 @@ def _load_image_from_data_url(image_url: str):
return load_image_from_base64(image_base64)
def _load_image_from_file(file_path: str) -> Image.Image:
# Load image directly from file
return Image.open(file_path)
def fetch_image(image_url: str, *, image_mode: str = "RGB") -> Image.Image:
"""
Load a PIL image from a HTTP or base64 data URL.
......@@ -43,6 +48,11 @@ def fetch_image(image_url: str, *, image_mode: str = "RGB") -> Image.Image:
elif image_url.startswith('data:image'):
image = _load_image_from_data_url(image_url)
elif os.path.isfile(image_url):
# Load image from local file path
image = _load_image_from_file(image_url)
else:
raise ValueError("Invalid 'image_url': A valid 'image_url' must start "
"with either 'data:image' or 'http'.")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment