사용법 (로컬·클라우드 실행)

사용법 (로컬·클라우드 실행)

moondream은 로컬에서 직접 실행할 수도, 클라우드 API로 쓸 수도 있어요. 로컬에서는 Hugging Face Transformers 통합으로 모델을 로드해요.

로컬 실행 (transformers)

vikhyatk/moondream2 모델을 trust_remote_code=True로 로드해요. encode_image로 이미지를 인코딩한 뒤 answer_question으로 질문에 답을 받는 흐름이에요.

from transformers import AutoModelForCausalLM, AutoTokenizer
from PIL import Image

model_id = "vikhyatk/moondream2"
model = AutoModelForCausalLM.from_pretrained(model_id, trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)

image = Image.open('/path/to/image.jpg')
enc_image = model.encode_image(image)
answer = model.answer_question(enc_image, "What is this?", tokenizer)

print(answer)

클라우드 API (Python)

moondream 공식 파이썬 패키지를 쓰면 API 키로 바로 사용할 수 있어요.

pip install moondream
import moondream as md
from PIL import Image

model = md.vl(api_key="YOUR_API_KEY")
image = Image.open("path/to/image.jpg")
result = model.query(image, "What is in this image?")
print(result["answer"])

API 키는 Moondream Cloud Console에서 발급받을 수 있어요. 자체 하드웨어에서 돌리고 싶다면 공식 "running locally" 가이드를 참고하면 돼요.

더 알아보기