Views
No views yet
1from transformers import AutoTokenizer, AutoModelForCausalLM
2from peft import PeftModel
3import torch
4
5# Load base model and tokenizer
6base_model_name = "unsloth/Llama-3.2-3B-Instruct"
7model = AutoModelForCausalLM.from_pretrained(
8 base_model_name,
9 torch_dtype=torch.float16,
10 device_map="auto"
11)
12tokenizer = AutoTokenizer.from_pretrained(base_model_name)
13
14# Load LoRA adapter
15model = PeftModel.from_pretrained(model, "slavayosome/llama-3.2-3b-linkedin-lora")
16model = model.merge_and_unload()
17
18# Generate content
19prompt = \"\"\"### System
20You are an expert LinkedIn content creator. Generate high-quality LinkedIn content based on the specified parameters.
21
22Parameters:
23- Topic: AI in business
24- Tone: professional
25- Format: post
26- Length: medium
27- Target Audience: entrepreneurs
28
29### User
30Create a medium post about AI in business in a professional tone for entrepreneurs.
31
32### Assistant
33\"\"\"
34
35inputs = tokenizer(prompt, return_tensors="pt")
36outputs = model.generate(**inputs, max_new_tokens=512, temperature=0.7)
37response = tokenizer.decode(outputs[0], skip_special_tokens=True)
38print(response.split("### Assistant")[-1].strip())1from huggingface_hub import snapshot_download
2
3# Download adapter files
4adapter_path = snapshot_download(repo_id="slavayosome/llama-3.2-3b-linkedin-lora")adapter_model.safetensors: LoRA adapter weights (1.8GB)adapter_config.json: LoRA configurationtokenizer.json: Tokenizer vocabularytokenizer_config.json: Tokenizer configurationspecial_tokens_map.json: Special token mappingstraining_info.json: Training metadata1@misc{linkedin-content-generator-lora,
2 title={LinkedIn Content Generator LoRA Adapter},
3 author={Your Name},
4 year={2024},
5 publisher={HuggingFace},
6 url={https://huggingface.co/slavayosome/llama-3.2-3b-linkedin-lora}
7}