Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

llama vision #24

Merged
merged 6 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions tutorials/meta/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
version: '3.8'
services:
ollama:
volumes:
- ~/ollama/ollama:/root/.ollama
container_name: ollama
#pull_policy: always
tty: true
restart: unless-stopped
#restart: unless-stopped
image: ollama/ollama:0.4.0-rc5
ports:
- 11434:11434
- 21434:11434
deploy:
resources:
reservations:
Expand Down
37 changes: 37 additions & 0 deletions tutorials/meta/llama_vision.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from PIL import Image
import base64
import io
from ollama import Client
def image_to_base64(image_path):
# Open the image file
with Image.open(image_path) as img:
# Create a BytesIO object to hold the image data
buffered = io.BytesIO()
# Save the image to the BytesIO object in a specific format (e.g., PNG)
img.save(buffered, format="PNG")
# Get the byte data from the BytesIO object
img_bytes = buffered.getvalue()
# Encode the byte data to base64
img_base64 = base64.b64encode(img_bytes).decode('utf-8')
return img_base64


def test_code():
image_path = '/home/gaganyatri/Downloads/books-rec-1.jpeg' # Replace with your image path
base64_image = image_to_base64(image_path)
client = Client(host='http://localhost:21434')
response = client.chat(
model="x/llama3.2-vision:latest",
messages=[{
"role": "user",
"content": "Describe this image?",
"images": [base64_image]
}],
)

# Extract the model's response about the image
cleaned_text = response['message']['content'].strip()
print(f"Model Response: {cleaned_text}")
# Example usage

test_code()
11 changes: 11 additions & 0 deletions tutorials/meta/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
anyio==4.6.2.post1
certifi==2024.8.30
exceptiongroup==1.2.2
h11==0.14.0
httpcore==1.0.6
httpx==0.27.2
idna==3.10
ollama==0.3.3
pillow==11.0.0
sniffio==1.3.1
typing_extensions==4.12.2
Loading
Loading