mirror of
https://github.com/lucasjinreal/Namo-R1.git
synced 2026-01-14 06:17:15 +08:00
Merge pull request #8 from forensicmike/dev
Readme update and small fix to image loading
This commit is contained in:
commit
7a5ff97458
@ -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
|
||||||
|
|||||||
@ -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?')
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user