custom dataset img support base64 (#35280)
Signed-off-by: xjx <493337577@qq.com>
This commit is contained in:
@@ -305,9 +305,11 @@ def process_image(image: Any) -> Mapping[str, Any]:
|
|||||||
a JPEG in memory. - Encodes the JPEG data as a base64 string. - Returns
|
a JPEG in memory. - Encodes the JPEG data as a base64 string. - Returns
|
||||||
a dictionary with the image as a base64 data URL.
|
a dictionary with the image as a base64 data URL.
|
||||||
|
|
||||||
3. String input: - Treats the string as a URL or local file path. -
|
3. String input: - Treats the string as a URL, local file path, or base64
|
||||||
Prepends "file://" if the string doesn't start with "http://" or
|
encoded data. - If string starts with "data:image/", treats as base64.
|
||||||
"file://". - Returns a dictionary with the image URL.
|
- If string starts with "http://", "https://", or "file://", treats as URL.
|
||||||
|
- Otherwise treats as local file path and prepends "file://".
|
||||||
|
- Returns a dictionary with the image URL or base64 data.
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
ValueError: If the input is not a supported type.
|
ValueError: If the input is not a supported type.
|
||||||
@@ -327,14 +329,14 @@ def process_image(image: Any) -> Mapping[str, Any]:
|
|||||||
if isinstance(image, str):
|
if isinstance(image, str):
|
||||||
image_url = (
|
image_url = (
|
||||||
image
|
image
|
||||||
if image.startswith(("http://", "https://", "file://"))
|
if image.startswith(("http://", "https://", "file://", "data:image/"))
|
||||||
else f"file://{image}"
|
else f"file://{image}"
|
||||||
)
|
)
|
||||||
return {"type": "image_url", "image_url": {"url": image_url}}
|
return {"type": "image_url", "image_url": {"url": image_url}}
|
||||||
|
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"Invalid image input {image}. Must be a PIL.Image.Image"
|
f"Invalid image input {image}. Must be a PIL.Image.Image, "
|
||||||
" or str or dictionary with raw image bytes."
|
"str (URL, file path, or base64 data URL), or dictionary with raw image bytes."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user