Skip to content

Commit

Permalink
llama vision (#24)
Browse files Browse the repository at this point in the history
* update llama file

* test spirit-lm

* add gradio ui

* choose vision server

* progres- sarvam1

* update -steps

---------

Co-authored-by: sachin <>
  • Loading branch information
sachinsshetty authored Oct 31, 2024
1 parent 8a53f6c commit 64c1ff9
Show file tree
Hide file tree
Showing 7 changed files with 6,884 additions and 6,871 deletions.
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

0 comments on commit 64c1ff9

Please sign in to comment.