Spaces:
Sleeping
Sleeping
import gradio as gr | |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM | |
from peft import PeftModel, PeftConfig | |
config = PeftConfig.from_pretrained("zeyadusf/FlanT5Summarization-samsum") | |
base_model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-large") | |
model = PeftModel.from_pretrained(base_model, "zeyadusf/FlanT5Summarization-samsum") | |
def summarize(text): | |
inputs = tokenizer(text, return_tensors="pt", truncation=True) | |
summary_ids = model.generate(inputs.input_ids, max_length=512, min_length=64, length_penalty=2.0, num_beams=4, early_stopping=True) | |
return tokenizer.decode(summary_ids[0], skip_special_tokens=True) | |
# Define the Gradio interface | |
iface = gr.Interface(fn=summarize, inputs="text", outputs="text", title="Summarization with PEFT") | |
iface.launch() | |