Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenDAS
vllm_cscc
Commits
a89ac72c
Commit
a89ac72c
authored
Nov 01, 2024
by
zhuwenwen
Browse files
support multi image input of local files
parent
04d33670
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
0 deletions
+10
-0
vllm/multimodal/utils.py
vllm/multimodal/utils.py
+10
-0
No files found.
vllm/multimodal/utils.py
View file @
a89ac72c
...
...
@@ -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'."
)
...
...
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