CoolFace
Apppublic

Sham786/CoEdit

sourceHugging Facemitupdated 3y agoView on Hugging Face
0likes
app.py27 linesDownload Raw Back to root
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