from unsloth import FastVisionModelfrom qwen_vl_utils import process_vision_infofrom PIL import Image # Load modelmodel, tokenizer = FastVisionModel.from_pretrained( "Nalandadata/DrishtiTable-Qwen2.5-VL-7B", max_seq_length=4096, load_in_4bit=True,)FastVisionModel.for_inference(model) # Prepare inputimage = Image.open("table.png").convert("RGB")messages = [ {"role": "system", "content": "You are a table structure recognition expert. Given an image of a table, output the HTML representation of the table structure and content. Use <table>, <thead>, <tbody>, <tr>, <th>, <td> tags. Use colspan and rowspan attributes for merged cells. Output ONLY the HTML table, nothing else."}, {"role": "user", "content": [ {"type": "image", "image": image}, {"type": "text", "text": "Convert this table image to HTML. Output only the HTML table structure with cell content."}, ]},] # Generatetext = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)image_inputs, video_inputs = process_vision_info(messages)inputs = tokenizer(text=[text], images=image_inputs, videos=video_inputs, padding=True, return_tensors="pt").to(model.device) output = model.generate(**inputs, max_new_tokens=4096, do_sample=False)generated = [o[len(i):] for i, o in zip(inputs.input_ids, output)]html = tokenizer.batch_decode(generated, skip_special_tokens=True)[0].strip()print(html)