Sham786/CoEdit
0
1import gradio as gr2from transformers import AutoTokenizer, T5ForConditionalGeneration3 4# Load the CoEdIT-xl model and tokenizer5tokenizer = AutoTokenizer.from_pretrained("grammarly/coedit-xxl")6model = T5ForConditionalGeneration.from_pretrained("grammarly/coedit-xxl")7 8def edit_text(input_text):9 # Tokenize input text10 input_ids = tokenizer(input_text, return_tensors="pt").input_ids11 # Generate edited text12 outputs = model.generate(input_ids, max_length=1005)13 edited_text = tokenizer.decode(outputs[0], skip_special_tokens=True)14 return edited_text15 16# Create a Gradio interface17iface = gr.Interface(18 fn=edit_text,19 inputs=gr.Textbox(label="Enter a sentence to edit:"),20 outputs=gr.Textbox(label="Edited sentence:"),21 title="CoEdIT Text Editor",22 description="Edit text using the CoEdIT-xl model.",23)24 25if __name__ == "__main__":26 iface.launch(share=False)27 