import jsonfrom peft import PeftModelfrom transformers import AutoModelForCausalLM, AutoTokenizer base = "Qwen/Qwen2.5-1.5B-Instruct"tokenizer = AutoTokenizer.from_pretrained(base)model = AutoModelForCausalLM.from_pretrained(base, dtype="auto", device_map="auto")model = PeftModel.from_pretrained(model, "jeekoo1/qwen2.5-1.5b-text2json-lora") instruction = ( "Extract the named entities from the text and return only a JSON object with exactly these keys: " "art, building, event, location, organization, other, person, product. " "Each value is a list of the entity names exactly as they appear in the text. " "Use an empty list when there are none.")text = "Marie Curie worked at the University of Paris and won the Nobel Prize in 1911."messages = [{"role": "system", "content": instruction}, {"role": "user", "content": text}]inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device)out = model.generate(inputs, max_new_tokens=200, do_sample=False)print(json.loads(tokenizer.decode(out[0, inputs.shape[1]:], skip_special_tokens=True)))