Spaces:
No application file
No application file
File size: 685 Bytes
37e8503 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
from transformers import AutoModelForCausalLM, AutoTokenizer
from PIL import Image
# Model and tokenizer loading
model_id = "vikhyatk/moondream2"
revision = "2024-03-06"
model = AutoModelForCausalLM.from_pretrained(
model_id, trust_remote_code=True, revision=revision
)
tokenizer = AutoTokenizer.from_pretrained(model_id, revision=revision)
# Image loading
image_path = 'demp.png'
image = Image.open(image_path)
# Display the image
image.show()
# Encoding the image
enc_image = model.encode_image(image)
# Asking the model to describe the image
description = model.answer_question(enc_image, "Describe this image.", tokenizer)
print("Generated Description:", description)
|