Views
No views yet

pip install git+https://github.com/TIGER-AI-Lab/Mantis.git1from mantis.models.mllava import chat_mllava
2from PIL import Image
3import torch
4
5
6image1 = "image1.jpg"
7image2 = "image2.jpg"
8images = [Image.open(image1), Image.open(image2)]
9
10# load processor and model
11from mantis.models.mllava import MLlavaProcessor, LlavaForConditionalGeneration
12processor = MLlavaProcessor.from_pretrained("TIGER-Lab/Mantis-bakllava-7b")
13model = LlavaForConditionalGeneration.from_pretrained("TIGER-Lab/Mantis-bakllava-7b", device_map="auto", torch_dtype=torch.bfloat16, attn_implementation="flash_attention_2")
14
15# chat
16text = "<image> <image> What's the difference between these two images? Please describe as much as you can."
17response, history = chat_mllava(text, images, model, processor)
18
19print("USER: ", text)
20print("ASSISTANT: ", response)
21# The image on the right has a larger number of wallets displayed compared to the image on the left. The wallets in the right image are arranged in a grid pattern, while the wallets in the left image are displayed in a more scattered manner. The wallets in the right image have various colors, including red, purple, and brown, while the wallets in the left image are primarily brown.
22
23text = "How many items are there in image 1 and image 2 respectively?"
24response, history = chat_mllava(text, images, model, processor, history=history)
25
26print("USER: ", text)
27print("ASSISTANT: ", response)
28# There are two items in image 1 and four items in image 2.