From 606627c49d87b14868fe02beb4d8aa5615d684d8 Mon Sep 17 00:00:00 2001 From: forensicmike1 Date: Mon, 24 Feb 2025 07:13:31 -0700 Subject: [PATCH 1/2] Add torch import to readme. Improve image handling, accepting PIL images and dealing with filenames that have spaces in them. --- namo/utils/infer_utils.py | 7 ++++++- readme.md | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/namo/utils/infer_utils.py b/namo/utils/infer_utils.py index 151b6a2..7a2651a 100644 --- a/namo/utils/infer_utils.py +++ b/namo/utils/infer_utils.py @@ -3,6 +3,7 @@ from PIL import Image import base64 from threading import Thread import io +import os from transformers import TextStreamer try: @@ -12,6 +13,8 @@ except ImportError: def load_image(image_file): + if isinstance(image_file, Image.Image): + return image_file if image_file.startswith("http") or image_file.startswith("https"): response = requests.get(image_file) image = Image.open(io.BytesIO(response.content)).convert("RGB") @@ -21,7 +24,9 @@ def load_image(image_file): def load_multi_images_maybe(image_files, splitter=" "): - if isinstance(image_files, str): + if isinstance(image_files, Image.Image): + return [image_files] + if isinstance(image_files, str) and not os.path.exists(image_files): images = image_files.split(splitter) else: images = image_files diff --git a/readme.md b/readme.md index 7c5c168..d3ab982 100644 --- a/readme.md +++ b/readme.md @@ -68,6 +68,7 @@ pip install -U namo A simple demo would be: ```python +import torch from namo.api.vl import VLInfer # model will download automatically @@ -76,6 +77,7 @@ model = VLInfer( ) # default will have streaming +# this method accepts a single path or PIL image, or an array of same. model.generate(images='images/cats.jpg', prompt='what is this?') ``` From 487211e8c71a807bdaad9b09aee4969b3dfe00d1 Mon Sep 17 00:00:00 2001 From: forensicmike1 Date: Mon, 24 Feb 2025 07:18:01 -0700 Subject: [PATCH 2/2] Adjust wording in readme --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index d3ab982..25f8c81 100644 --- a/readme.md +++ b/readme.md @@ -77,7 +77,7 @@ model = VLInfer( ) # default will have streaming -# this method accepts a single path or PIL image, or an array of same. +# this method accepts a single path, url, or PIL image, or an array of same. model.generate(images='images/cats.jpg', prompt='what is this?') ```