# app.py import gradio as gr from transformers import AutoTokenizer, AutoModelForCausalLM from peft import PeftModel import torch # Load the model and tokenizer adapter_model_name = "acezxn/SOC_Task_Generation_Base" base_model_name = "unsloth/Llama-3.2-3B-Instruct-unsloth-bnb-4bit" # You may want to change this to a standard model name # Load the tokenizer and model for CPU use (no bitsandbytes) tokenizer = AutoTokenizer.from_pretrained(base_model_name) # Load model for CPU usage without 4-bit quantization base_model = AutoModelForCausalLM.from_pretrained( base_model_name, # Do not use bitsandbytes for quantization, just use the normal model load_in_4bit=False, # Ensure not using 4-bit quantization device_map=None, # Use CPU (no device mapping needed) trust_remote_code=True # If necessary for running with remote code ) # Move model to CPU (explicit, but optional) base_model.to('cpu') # Load the LoRA adapter adapter_model = PeftModel.from_pretrained(base_model, adapter_model_name) # Function to generate a response using the model def generate_response(input_text): inputs = tokenizer(input_text, return_tensors="pt").to('cpu') # Ensure inputs are on CPU outputs = adapter_model.generate(**inputs) response = tokenizer.decode(outputs[0], skip_special_tokens=True) return response # Create Gradio interface iface = gr.Interface(fn=generate_response, inputs=gr.Textbox(lines=2, placeholder="Enter your input here..."), outputs=gr.Textbox(), title="Llama LORA Adapter - SOC Task Generation", description="This is a Gradio app that uses a Llama LORA adapter (acezxn/SOC_Task_Generation_Base) with the base model Llama-3.2-3B-Instruct-unsloth-bnb-4bit to generate task-related responses.") # Launch the interface if __name__ == "__main__": iface.launch()