Spaces:
Runtime error

unsloth / app.py
Chuxia-sys's picture
Update app.py
5194bb0 verified
Raw History Blame Contribute Delete
1.16 kB
import gradio as gr
from transformers import AutoTokenizer, AutoModelForCausalLM
from peft import PeftModel
# Base model (must match what you used in training with Unsloth)
BASE_MODEL = "mistralai/Mistral-7B-v0.1"
ADAPTER = "Chuxia-sys/ph-travel-planner"
# Load tokenizer
tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL)
# Load base model
model = AutoModelForCausalLM.from_pretrained(
BASE_MODEL,
load_in_4bit=True,
device_map="auto"
)
# Apply LoRA adapter
model = PeftModel.from_pretrained(model, ADAPTER)
# Chat function
def chat_with_bot(user_input):
inputs = tokenizer(user_input, return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens=200)
reply = tokenizer.decode(outputs[0], skip_special_tokens=True)
return reply
# Gradio UI
iface = gr.Interface(
fn=chat_with_bot,
inputs=gr.Textbox(lines=2, placeholder="Type your travel plan request..."),
outputs=gr.Textbox(label="Travel Planner AI"),
title="PH Travel Planner 🌍",
description="Chat with the AI to generate customized travel plans for the Philippines."
)
if __name__ == "__main__":
iface.launch()