| import gradio as gr |
| import peft |
| from peft import PeftModel, PeftConfig |
| from transformers import AutoModelForCausalLM, AutoTokenizer |
| import torch |
|
|
| |
| config = PeftConfig.from_pretrained("PhantHive/llama-2-7b-momo") |
| model = AutoModelForCausalLM.from_pretrained("NousResearch/Llama-2-7b-chat-hf") |
| model = PeftModel.from_pretrained(model, "PhantHive/llama-2-7b-momo") |
|
|
| |
| tokenizer = AutoTokenizer.from_pretrained("NousResearch/Llama-2-7b-chat-hf") |
|
|
| def greet(text): |
| batch = tokenizer(f"'{text}' ->: ", return_tensors='pt') |
|
|
| with torch.cuda.amp.autocast(): |
| output_tokens = model.generate(**batch, max_new_tokens=100) |
|
|
| return tokenizer.decode(output_tokens[0], skip_special_tokens=True) |
|
|
|
|
| iface = gr.Interface(fn=greet, inputs="text", outputs="text") |
| iface.launch() |