chatbot try
Browse files
app.py
CHANGED
|
@@ -1,7 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from unsloth import FastLanguageModel
|
| 2 |
+
from peft import PeftModel
|
| 3 |
+
from transformers import AutoTokenizer
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
+
base_model_name = "unsloth/Llama-3.2-3B-Instruct"
|
| 7 |
+
base_model, tokenizer = FastLanguageModel.from_pretrained(
|
| 8 |
+
model_name=base_model_name,
|
| 9 |
+
max_seq_length=2048,
|
| 10 |
+
dtype=None,
|
| 11 |
+
load_in_4bit=True
|
| 12 |
+
)
|
| 13 |
|
| 14 |
+
# lora adapters from my Hugging Face model
|
| 15 |
+
lora_model_name = "oskaralf/lora_model" # Hugging Face repository for LoRA adapters
|
| 16 |
+
model = PeftModel.from_pretrained(base_model, lora_model_name)
|
| 17 |
+
FastLanguageModel.for_inference(model)
|
| 18 |
+
|
| 19 |
+
def chatbot(input_text):
|
| 20 |
+
inputs = tokenizer(input_text, return_tensors="pt").to("cuda")
|
| 21 |
+
outputs = model.generate(input_ids=inputs["input_ids"], max_new_tokens=64)
|
| 22 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 23 |
+
return response
|
| 24 |
+
|
| 25 |
+
iface = gr.Interface(fn=chatbot, inputs="text", outputs="text", title="Chatbot")
|
| 26 |
+
iface.launch()
|