IT 인터넷/일반
[Ollama] 이미지 이용하기
Banjubu
2024. 12. 6. 19:13
반응형
로컬에 Ollama 서버를 실행했다고 가정할게요.
$ ollama serve
from ollama import generate
from io import BytesIO
from PIL import Image
import os
def process_image(image_file):
with Image.open(image_file) as img:
with BytesIO() as buffer:
img.save(buffer, format='PNG')
image_bytes = buffer.getvalue()
for response in generate(model='llava:latest',
prompt='What\'s in the image?',
images=[image_bytes],
stream=True):
print(response['response'], end='', flush=True)
if __name__ == "__main__":
try:
image_path = input("Enter the image path: ").strip()
base64_image = process_image(image_path)
except Exception as e:
print(f"An error occurred: {e}")
터미널에서 실행하고 이미지를 끌어다 넣으면 경로가 들어가요.
반응형
LIST