MCPcopy Create free account
hub / github.com/Open-Bee/DataStudio / parse_file

Function parse_file

datastudio/utils/vision.py:104–125  ·  view source on GitHub ↗

Parse input to determine if it's an image file. Args: s: Input to parse (string path, PIL Image, list, or other). image_name: Name to use for image type identification. Returns: Tuple of (mime_type, value) where mime_type is None for non-images.

(s: Any, image_name: str = "image")

Source from the content-addressed store, hash-verified

102
103
104def parse_file(s: Any, image_name: str = "image") -> Tuple[Optional[str], Any]:
105 """Parse input to determine if it's an image file.
106
107 Args:
108 s: Input to parse (string path, PIL Image, list, or other).
109 image_name: Name to use for image type identification.
110
111 Returns:
112 Tuple of (mime_type, value) where mime_type is None for non-images.
113 """
114 if isinstance(s, list):
115 return (image_name, s)
116 elif isinstance(s, Image.Image):
117 return (image_name, s)
118 elif isinstance(s, str):
119 # Check base64 data URL before osp.exists() to avoid stat()
120 # syscall on multi-MB strings.
121 if s.startswith("data:image"):
122 return (image_name, s)
123 elif osp.exists(s) and s != "." and osp.isfile(s):
124 return (image_name, s)
125 return (None, s)
126
127
128def load_and_resize_image(img_path: str, resize_size: int):

Callers 4

preproc_contentMethod · 0.90
test_parse_file_imageMethod · 0.90
test_parse_file_noneMethod · 0.90

Calls 1

existsMethod · 0.80

Tested by 3

test_parse_file_imageMethod · 0.72
test_parse_file_noneMethod · 0.72