Skip to content

Commit

Permalink
rename model folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Blaizzy committed Apr 30, 2024
1 parent 51f0680 commit 56f8fdc
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 22 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
45 changes: 23 additions & 22 deletions mlx_vlm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
PreTrainedTokenizer,
PreTrainedTokenizerFast,
)
from transformers.image_utils import load_image

from .models.base import BaseImageProcessor
from .sample_utils import top_p_sampling
Expand Down Expand Up @@ -562,28 +563,28 @@ def convert(
upload_to_hub(mlx_path, upload_repo, hf_path)


def load_image(image_source):
"""
Helper function to load an image from either a URL or file.
"""
if image_source.startswith(("http://", "https://")):
try:
response = requests.get(image_source, stream=True)
response.raise_for_status()
return Image.open(response.raw)
except Exception as e:
raise ValueError(
f"Failed to load image from URL: {image_source} with error {e}"
)
elif Path(image_source).is_file():
try:
return Image.open(image_source)
except IOError as e:
raise ValueError(f"Failed to load image {image_source} with error: {e}")
else:
raise ValueError(
f"The image {image_source} must be a valid URL or existing file."
)
# def load_image(image_source):
# """
# Helper function to load an image from either a URL or file.
# """
# if image_source.startswith(("http://", "https://")):
# try:
# response = requests.get(image_source, stream=True)
# response.raise_for_status()
# return Image.open(response.raw)
# except Exception as e:
# raise ValueError(
# f"Failed to load image from URL: {image_source} with error {e}"
# )
# elif Path(image_source).is_file():
# try:
# return Image.open(image_source)
# except IOError as e:
# raise ValueError(f"Failed to load image {image_source} with error: {e}")
# else:
# raise ValueError(
# f"The image {image_source} must be a valid URL or existing file."
# )


def prepare_inputs(image_processor, processor, image, prompt):
Expand Down

0 comments on commit 56f8fdc

Please sign in to comment.