Views
No views yet


1processor = AutoProcessor.from_pretrained("Syed-Hasan-8503/Idefics2-8B-SFT")
2model = AutoModelForVision2Seq.from_pretrained("Syed-Hasan-8503/Idefics2-8B-SFT",).to(DEVICE)
3
4# Create inputs
5messages = [
6 {
7 "role": "user",
8 "content": [
9 {"type": "image"},
10 {"type": "text", "text": "What do we see in this image?"},
11 ]
12 },
13 {
14 "role": "assistant",
15 "content": [
16 {"type": "text", "text": "In this image, we can see the city of New York, and more specifically the Statue of Liberty."},
17 ]
18 },
19 {
20 "role": "user",
21 "content": [
22 {"type": "image"},
23 {"type": "text", "text": "And how about this image?"},
24 ]
25 },
26]
27prompt = processor.apply_chat_template(messages, add_generation_prompt=True)
28inputs = processor(text=prompt, images=[image1, image2], return_tensors="pt")
29inputs = {k: v.to(DEVICE) for k, v in inputs.items()}
30
31
32# Generate
33generated_ids = model.generate(**inputs, max_new_tokens=500)
34generated_texts = processor.batch_decode(generated_ids, skip_special_tokens=True)
35
36print(generated_texts)
37# ['User: What do we see in this image? \nAssistant: In this image, we can see the city of New York, and more specifically the Statue of Liberty. \nUser: And how about this image? \nAssistant: In this image we can see buildings, trees, lights, water and sky.']