Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline | |
| # Load PEGASUS model | |
| model_name = "tuner007/pegasus_paraphrase" | |
| tokenizer = AutoTokenizer.from_pretrained(model_name) | |
| model = AutoModelForSeq2SeqLM.from_pretrained(model_name) | |
| # Initialize pipeline | |
| paraphrase_pipeline = pipeline("text2text-generation", model=model, tokenizer=tokenizer, truncation=True) | |
| # Paraphrase function | |
| def paraphrase_text(text): | |
| sentences = text.split(". ") # Simple sentence split | |
| paraphrased_sentences = [paraphrase_pipeline(sentence, max_length=60, do_sample=False)[0]['generated_text'] for sentence in sentences] | |
| return " ".join(paraphrased_sentences) | |
| # Gradio interface | |
| demo = gr.Interface(fn=paraphrase_text, inputs="text", outputs="text", title="Text Paraphraser") | |
| # Launch app | |
| demo.launch() | |