File size: 1,902 Bytes
a72f1b5
2f3eac6
a72f1b5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2f3eac6
a72f1b5
 
2f3eac6
a72f1b5
 
2f3eac6
a72f1b5
 
 
 
 
 
2f3eac6
a72f1b5
 
 
 
 
 
2f3eac6
a72f1b5
2f3eac6
a72f1b5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# 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()