1from transformers import AutoModelForCausalLM, AutoTokenizer
2from peft import PeftModel
3import torch
4
5# Load base model and LoRA adapter
6BASE_MODEL = "Qwen/Qwen2.5-1.5B-Instruct"
7LORA_ADAPTER = "YOUR_HF_USERNAME/sifera-v2-qwen-lora"
8
9tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL, trust_remote_code=True)
10base_model = AutoModelForCausalLM.from_pretrained(
11 BASE_MODEL,
12 torch_dtype=torch.float32,
13 device_map="cpu",
14 low_cpu_mem_usage=True,
15 trust_remote_code=True
16)
17model = PeftModel.from_pretrained(base_model, LORA_ADAPTER)
18
19# Summarize text
20text = "Your long document text here..."
21prompt = f"Summarize the following text:\n\n{text}\n\nSummary:"
22
23inputs = tokenizer(prompt, return_tensors="pt")
24outputs = model.generate(
25 inputs.input_ids,
26 max_new_tokens=256,
27 temperature=0.7,
28 top_p=0.9,
29 do_sample=True
30)
31
32result = tokenizer.decode(outputs[0], skip_special_tokens=True)
33print(result)
1import gradio as gr
2from transformers import AutoModelForCausalLM, AutoTokenizer
3from peft import PeftModel
4
5BASE_MODEL = "Qwen/Qwen2.5-1.5B-Instruct"
6LORA_ADAPTER = "YOUR_HF_USERNAME/sifera-v2-qwen-lora"
7
8tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL, trust_remote_code=True)
9base_model = AutoModelForCausalLM.from_pretrained(BASE_MODEL, torch_dtype=torch.float32, device_map="cpu", trust_remote_code=True)
10model = PeftModel.from_pretrained(base_model, LORA_ADAPTER)
11
12def process(text, action):
13 prompt = f"{action} the following:\n\n{text}\n\n{action.capitalize()}:"
14 inputs = tokenizer(prompt, return_tensors="pt")
15 outputs = model.generate(inputs.input_ids, max_new_tokens=256)
16 return tokenizer.decode(outputs[0], skip_special_tokens=True)
17
18demo = gr.Interface(
19 fn=process,
20 inputs=[
21 gr.Textbox(label="Input Text", lines=10),
22 gr.Radio(["Summarize", "Notes", "Key Points", "Q&A"], label="Action")
23 ],
24 outputs=gr.Textbox(label="Output", lines=10)
25)
26
27demo.launch()
1from fastapi import FastAPI
2from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
3from peft import PeftModel
4
5app = FastAPI()
6
7# Load model with LoRA
8BASE_MODEL = "Qwen/Qwen2.5-1.5B-Instruct"
9LORA_ADAPTER = "YOUR_HF_USERNAME/sifera-v2-qwen-lora"
10tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL, trust_remote_code=True)
11base_model = AutoModelForCausalLM.from_pretrained(BASE_MODEL, device_map="cpu", trust_remote_code=True)
12model = PeftModel.from_pretrained(base_model, LORA_ADAPTER)
13
14generator = pipeline("text-generation", model=model, tokenizer=tokenizer)
15
16@app.post("/summarize")
17async def summarize(text: str):
18 prompt = f"Summarize: {text}"
19 result = generator(prompt, max_new_tokens=256)
20 return {"summary": result[0]["generated_text"]}
1curl -X POST "http://localhost:8000/summarize" \
2 -H "Content-Type: application/json" \
3 -d '{"text": "Your document text here..."}'
1generation_config = {
2 "do_sample": True,
3 "temperature": 0.7,
4 "top_p": 0.9,
5 "top_k": 50,
6 "max_new_tokens": 512,
7 "repetition_penalty": 1.1
8}
1@software{sifera_v2_qwen_2025,
2 author = {Vaghani, Shivam},
3 title = {Sifera AI V2 - Qwen LoRA Adapter},
4 year = {2025},
5 publisher = {Hugging Face},
6 url = {https://huggingface.co/YOUR_USERNAME/sifera-v2-qwen-lora}
7}