Merge pull request #8 from forensicmike/dev

Readme update and small fix to image loading
This commit is contained in:
MagicSource 2025-02-25 10:25:11 +08:00 committed by GitHub
commit 7a5ff97458
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 1 deletions

View File

@ -3,6 +3,7 @@ from PIL import Image
import base64 import base64
from threading import Thread from threading import Thread
import io import io
import os
from transformers import TextStreamer from transformers import TextStreamer
try: try:
@ -12,6 +13,8 @@ except ImportError:
def load_image(image_file): def load_image(image_file):
if isinstance(image_file, Image.Image):
return image_file
if image_file.startswith("http") or image_file.startswith("https"): if image_file.startswith("http") or image_file.startswith("https"):
response = requests.get(image_file) response = requests.get(image_file)
image = Image.open(io.BytesIO(response.content)).convert("RGB") 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=" "): 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) images = image_files.split(splitter)
else: else:
images = image_files images = image_files

View File

@ -68,6 +68,7 @@ pip install -U namo
A simple demo would be: A simple demo would be:
```python ```python
import torch
from namo.api.vl import VLInfer from namo.api.vl import VLInfer
# model will download automatically # model will download automatically
@ -76,6 +77,7 @@ model = VLInfer(
) )
# default will have streaming # default will have streaming
# 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?') model.generate(images='images/cats.jpg', prompt='what is this?')
``` ```