Spaces:
Runtime error
Runtime error
Download app.py from Chuxia-sys/unsloth: direct link, hf CLI and curl.
- Browser
- Download file 1.16 kB
-
https://huggingface.co/spaces/Chuxia-sys/unsloth/resolve/main/app.py
- Command line
-
hf download hf://spaces/Chuxia-sys/unsloth/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Chuxia-sys/unsloth/resolve/main/app.py
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() | |