Download run.py from kaivoss/Clover-Preview-VL: direct link, hf CLI and curl.
- Browser
- Download file 1.1 kB
-
https://huggingface.co/kaivoss/Clover-Preview-VL/resolve/main/run.py
- Command line
-
hf download hf://kaivoss/Clover-Preview-VL/run.py
-
curl -L -o run.py https://huggingface.co/kaivoss/Clover-Preview-VL/resolve/main/run.py
1.1 kB
| """Ask Clover-Preview-VL about an image (Hugging Face path; slow). python run.py photo.jpg "What is shown?" [--no-think]""" | |
| import sys | |
| import torch | |
| from huggingface_hub import snapshot_download | |
| from PIL import Image | |
| from transformers import AutoTokenizer | |
| from clover_sft.model import CloverForSFT | |
| from clover_vl import load_processor, load_vision, vl_generate | |
| here = snapshot_download("kaivoss/Clover-Preview-VL") | |
| tok = AutoTokenizer.from_pretrained(here) | |
| lm = CloverForSFT.from_pretrained(here, dtype=torch.bfloat16, device_map="cuda").eval() | |
| vision = load_vision("cuda", path=here).eval() | |
| args = [a for a in sys.argv[1:] if a != "--no-think"] | |
| image = Image.open(args[0]) | |
| question = args[1] if len(args) > 1 else "Describe this image in detail." | |
| if "--no-think" in sys.argv: | |
| print(vl_generate(lm, vision, tok, load_processor(), image, question, max_new_tokens=512)) | |
| else: | |
| reasoning, answer, _ = vl_generate(lm, vision, tok, load_processor(), image, question, think=True, | |
| max_new_tokens=2048) | |
| print(f"<think>\n{reasoning}\n</think>\n\n{answer}") | |