|
import gradio as gr |
|
from peft import PeftModel, PeftConfig |
|
from transformers import AutoModelForCausalLM, AutoTokenizer |
|
import torch |
|
|
|
|
|
config = PeftConfig.from_pretrained("phearion/bigbrain-v0.0.1") |
|
model = AutoModelForCausalLM.from_pretrained("mistralai/Mistral-7B-v0.1") |
|
model = PeftModel.from_pretrained(model, "phearion/bigbrain-v0.0.1") |
|
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-v0.1") |
|
|
|
|
|
|
|
def greet(text): |
|
batch = tokenizer(f"'{text}' ->: ", return_tensors='pt') |
|
|
|
|
|
with torch.cuda.amp.autocast(): |
|
output_tokens = model.generate(**batch, max_new_tokens=20) |
|
|
|
return tokenizer.decode(output_tokens[0], skip_special_tokens=True) |
|
|
|
|
|
iface = gr.Interface(fn=greet, inputs="text", outputs="text") |
|
iface.launch() |