| import gradio as gr |
| from transformers import AutoTokenizer, AutoModelForCausalLM |
| from peft import PeftModel |
| import os |
| from huggingface_hub import login |
|
|
| login(token=os.environ.get("HF_TOKEN")) |
|
|
| BASE = "meta-llama/Llama-2-7b-hf" |
| LORA = "automorphic/LORA_20231221_040125_high_school_mathematics" |
|
|
| |
| tokenizer = AutoTokenizer.from_pretrained(BASE) |
| model = AutoModelForCausalLM.from_pretrained(BASE, device_map="auto") |
| model = PeftModel.from_pretrained(model, LORA) |
|
|
| |
| def solve_math(prompt): |
| inputs = tokenizer(prompt, return_tensors="pt").to(model.device) |
| outputs = model.generate(**inputs, max_new_tokens=100) |
| return tokenizer.decode(outputs[0], skip_special_tokens=True) |
|
|
| |
| iface = gr.Interface( |
| fn=solve_math, |
| inputs="text", |
| outputs="text", |
| title="High School Math Solver (LoRA)", |
| description="Type a math problem and the model will solve it step-by-step!" |
| ) |
|
|
| iface.launch() |
|
|