rxpbtn21's picture
Upload folder using huggingface_hub
10ba581 verified
raw
history blame
983 Bytes
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
from peft import PeftModel
import torch
# Load the tokenizer
tokenizer = AutoTokenizer.from_pretrained("rxpbtn21/t5-small-lora-summarizer")
# Load the base model and then the LoRA adapter
base_model = AutoModelForSeq2SeqLM.from_pretrained("t5-small", device_map="auto")
model = PeftModel.from_pretrained(base_model, "rxpbtn21/t5-small-lora-summarizer")
model.eval()
def summarize(text):
inputs = tokenizer(text, max_length=512, truncation=True, return_tensors="pt")
with torch.no_grad():
outputs = model.generate(inputs["input_ids"].to(model.device), num_beams=4, max_new_tokens=128, early_stopping=True)
summary = tokenizer.decode(outputs[0], skip_special_tokens=True)
return summary
# Create Gradio interface
iface = gr.Interface(fn=summarize, inputs="text", outputs="text", title="LoRA Fine-tuned T5-small Summarizer")
# Launch the interface
iface.launch(share=False)