from transformers import AutoModelForCausalLM, AutoTokenizerfrom peft import PeftModelimport torch base_id = "Qwen/Qwen2.5-7B-Instruct"adapter_id = "p-sahas/Qwen2.5-7B-Instruct-AlpaCare-MedInstruct-QLoRA-r16-5k-LoRA" tokenizer = AutoTokenizer.from_pretrained(adapter_id)base_model = AutoModelForCausalLM.from_pretrained( base_id, torch_dtype=torch.bfloat16 if torch.cuda.is_available() and torch.cuda.is_bf16_supported() else torch.float16, device_map="auto",)model = PeftModel.from_pretrained(base_model, adapter_id) messages = [ {"role": "system", "content": "You are a knowledgeable, empathetic medical AI assistant for educational purposes. Provide clear, accurate, evidence-based explanations. Do not diagnose conditions, prescribe medications, or assist with self-harm or illegal acts; always encourage consulting a qualified healthcare professional for personal medical decisions."}, {"role": "user", "content": "Explain the difference between Type 1 and Type 2 diabetes in simple terms."},]inputs = tokenizer.apply_chat_template( messages, tokenize=True, add_generation_prompt=True, return_tensors="pt").to(model.device)outputs = model.generate(inputs, max_new_tokens=256, do_sample=False)print(tokenizer.decode(outputs[0][inputs.shape[1]:], skip_special_tokens=True))