Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
+
import torch
|
| 4 |
+
from peft import PeftModel # LoRA integration
|
| 5 |
+
|
| 6 |
+
# Load the tokenizer and model
|
| 7 |
+
model_name = "MrSimple07/llama_chatbot"
|
| 8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 9 |
+
base_model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 10 |
+
|
| 11 |
+
# Load LoRA weights
|
| 12 |
+
model = PeftModel.from_pretrained(base_model, model_name)
|
| 13 |
+
|
| 14 |
+
# Ensure model is in evaluation mode
|
| 15 |
+
model.eval()
|
| 16 |
+
|
| 17 |
+
# Chat function
|
| 18 |
+
def chatbot_response(message):
|
| 19 |
+
inputs = tokenizer(message, return_tensors="pt").input_ids
|
| 20 |
+
outputs = model.generate(inputs, max_length=100, num_return_sequences=1)
|
| 21 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 22 |
+
return response
|
| 23 |
+
|
| 24 |
+
# Gradio interface
|
| 25 |
+
iface = gr.Interface(fn=chatbot_response,
|
| 26 |
+
inputs=gr.inputs.Textbox(lines=7, label="Input your message"),
|
| 27 |
+
outputs="text",
|
| 28 |
+
title="LLaMA Chatbot with LoRA",
|
| 29 |
+
description="This is a chatbot trained with LoRA on the LLaMA model.")
|
| 30 |
+
|
| 31 |
+
iface.launch()
|