1from transformers import AutoTokenizer, AutoModelForCausalLM, AutoProcessor
2from PIL import Image
3import torch
4
5model_id = "Lamapi/next-12b"
6
7model = AutoModelForCausalLM.from_pretrained(model_id)
8processor = AutoProcessor.from_pretrained(model_id) # For vision.
9tokenizer = AutoTokenizer.from_pretrained(model_id)
10
11# Read image
12image = Image.open("image.jpg")
13
14# Create a message in chat format
15messages = [
16 {"role": "system","content": [{"type": "text", "text": "You are Next-X1, a smart and concise AI assistant trained by Lamapi. Always respond in the user's language. Proudly made in Turkey."}]},
17
18 {
19 "role": "user","content": [{"type": "image", "image": image},
20 {"type": "text", "text": "Who is in this image?"}
21 ]
22 }
23]
24
25# Prepare input with Tokenizer
26prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
27inputs = processor(text=prompt, images=[image], return_tensors="pt")
28
29# Output from the model
30output = model.generate(**inputs, max_new_tokens=50)
31print(tokenizer.decode(output[0], skip_special_tokens=True))
32
33
1from transformers import AutoTokenizer, AutoModelForCausalLM
2import torch
3
4model_id = "Lamapi/next-12b"
5tokenizer = AutoTokenizer.from_pretrained(model_id)
6model = AutoModelForCausalLM.from_pretrained(model_id)
7
8# Chat message
9messages = [
10 {"role": "system", "content": "You are Next-X1, a smart and concise AI assistant trained by Lamapi. Always respond in the user's language. Proudly made in Turkey."},
11 {"role": "user", "content": "Hello, how are you?"}
12]
13
14# Prepare input with Tokenizer
15prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
16inputs = tokenizer(prompt, return_tensors="pt")
17
18# Output from the model
19output = model.generate(**inputs, max_new_tokens=50)
20print(tokenizer.decode(output[0], skip_special_tokens=True))
21