Create vision_model.py
Browse files- vision_model.py +13 -0
vision_model.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import AutoProcessor, AutoModelForVision2Seq
|
| 2 |
+
from PIL import Image
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
model_id = "llava-hf/llava-1.5-7b-hf"
|
| 6 |
+
processor = AutoProcessor.from_pretrained(model_id)
|
| 7 |
+
model = AutoModelForVision2Seq.from_pretrained(model_id, torch_dtype=torch.float16).cuda()
|
| 8 |
+
|
| 9 |
+
def describe_image(image_path, prompt="Describe this sculpt and any missing regions."):
|
| 10 |
+
image = Image.open(image_path).convert("RGB")
|
| 11 |
+
inputs = processor(prompt, image, return_tensors="pt").to("cuda", torch.float16)
|
| 12 |
+
output = model.generate(**inputs, max_new_tokens=150)
|
| 13 |
+
return processor.decode(output[0], skip_special_tokens=True)
|