Views
No views yet
pip install transformers timm einops bitsandbytes accelerate1import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM
3from PIL import Image
4
5DEVICE = "cuda"
6DTYPE = torch.float32 if DEVICE == "cpu" else torch.float16 # CPU doesn't support float16
7revision = "ac6c8fc0ba757c6c4d7d541fdd0e63618457350c"
8tokenizer = AutoTokenizer.from_pretrained("gokaygokay/moondream-prompt", revision=revision)
9moondream = AutoModelForCausalLM.from_pretrained("gokaygokay/moondream-prompt",trust_remote_code=True,
10 torch_dtype=DTYPE, device_map={"": DEVICE}, revision=revision)
11moondream.eval()
12
13image_path = "<image_path>"
14image = Image.open(image_path).convert("RGB")
15md_answer = moondream.answer_question(
16 moondream.encode_image(image),
17 "Describe this image and its style in a very detailed manner",
18 tokenizer=tokenizer,
19 )
20
21print(md_answer)
1@software{aydogan2024moondream_prompt,
2 author = {Aydoğan, Gökay},
3 title = {{moondream-prompt}},
4 year = {2024},
5 publisher = {Hugging Face},
6 url = {https://huggingface.co/gokaygokay/moondream-prompt},
7 note = {Model repository; cite the base model and upstream datasets as required.}
8}