Views
No views yet
1## load the model from my own huggingface
2from unsloth import FastVisionModel
3
4model, tokenizer = FastVisionModel.from_pretrained(
5 "Rohit-Katkar2003/qwen2-vl-8b-lora-finetune",
6 load_in_4bit=True
7)
8
9FastVisionModel.for_inference(model) # Enable for inference!
10question = "what are the components in diagram give me response in markdown format with all the connection and components?"
11url = "https://instrumentationtools.com/wp-content/uploads/2016/09/instrumentationtools.com_piping-and-instrumentation-diagram.jpg"
12res = requests.get(url)
13image = Image.open(BytesIO(res.content))
14messages = [
15 {"role": "user", "content": [
16 {"type": "image"},
17 {"type": "text", "text": question}
18 ]}
19]
20input_text = tokenizer.apply_chat_template(messages, add_generation_prompt = True)
21inputs = tokenizer(
22 image,
23 input_text,
24 add_special_tokens = False,
25 return_tensors = "pt",
26).to("cuda")
27
28from transformers import TextStreamer
29text_streamer = TextStreamer(tokenizer, skip_prompt = True)
30_ = model.generate(**inputs, streamer = text_streamer, max_new_tokens = 1024,
31 use_cache = True, temperature = 0.3, min_p = 0.1)
32