Spaces:
Sleeping
Sleeping
| from transformers import AutoTokenizer, AutoModelForSeq2SeqLM | |
| import gradio as gr | |
| # Load model and tokenizer | |
| tokenizer = AutoTokenizer.from_pretrained("google/pegasus-xsum") | |
| model = AutoModelForSeq2SeqLM.from_pretrained("google/pegasus-xsum") | |
| def summarize(text): | |
| # Tokenize input text | |
| inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=1024) | |
| # Generate summary | |
| summary_ids = model.generate(inputs["input_ids"]) | |
| # Decode and return the summary | |
| summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True) | |
| return summary | |
| # Create Gradio interface | |
| demo = gr.Interface( | |
| fn=summarize, | |
| inputs=gr.Textbox(lines=10, placeholder="Enter text to summarize...", label="Input Text"), | |
| outputs=gr.Textbox(lines=5, label="Summary"), | |
| title="Pegasus-XSum Text Summarizer", | |
| description="Enter text and get an abstractive summary using Google's Pegasus-XSum model." | |
| ) | |
| # Launch the app | |
| demo.launch() |