-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* base model added "modality" field * ovis add "modality = [MODALITY.IMAGE_TO_TEXT]" * qwen2_vl add "modality = [MODALITY.TEXT, MODALITY.IMAGE_TO_TEXT]" * fix test * cleanup * cleanup * change quant_override_files hint type to: Dict[str, Union[str | Dict[str, Any]]] * cleanup
- Loading branch information
1 parent
2707ac7
commit 33791ce
Showing
12 changed files
with
385 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
def batched(iterable, n: int, process_func): | ||
# batched('ABCDEFG', 3) → ABC DEF G | ||
assert n >= 1, "batch size must be at least one" | ||
from itertools import islice | ||
|
||
iterator = iter(iterable) | ||
|
||
while batch := tuple(islice(iterator, n)): | ||
if process_func is None: | ||
yield batch | ||
else: | ||
yield [process_func(item) for item in batch] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from PIL import Image | ||
from io import BytesIO | ||
import requests | ||
import base64 | ||
|
||
def fetch_image(ele: dict[str, str | Image.Image]) -> Image.Image: | ||
if "image" in ele: | ||
image = ele["image"] | ||
else: | ||
image = ele["image_url"] | ||
image_obj = None | ||
if isinstance(image, Image.Image): | ||
image_obj = image | ||
elif image.startswith("http://") or image.startswith("https://"): | ||
image_obj = Image.open(requests.get(image, stream=True).raw) | ||
elif image.startswith("file://"): | ||
image_obj = Image.open(image[7:]) | ||
elif image.startswith("data:image"): | ||
if "base64," in image: | ||
_, base64_data = image.split("base64,", 1) | ||
data = base64.b64decode(base64_data) | ||
image_obj = Image.open(BytesIO(data)) | ||
else: | ||
image_obj = Image.open(image) | ||
if image_obj is None: | ||
raise ValueError(f"Unrecognized image input, support local path, http url, base64 and PIL.Image, got {image}") | ||
return image_obj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.