File size: 884 Bytes
e4d8732
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import gradio as gr
from transformers import AutoTokenizer, T5ForConditionalGeneration

# Load the CoEdIT-xl model and tokenizer
tokenizer = AutoTokenizer.from_pretrained("grammarly/coedit-xl")
model = T5ForConditionalGeneration.from_pretrained("grammarly/coedit-xl")

def edit_text(input_text):
    # Tokenize input text
    input_ids = tokenizer(input_text, return_tensors="pt").input_ids
    # Generate edited text
    outputs = model.generate(input_ids, max_length=256)
    edited_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
    return edited_text

# Create a Gradio interface
iface = gr.Interface(
    fn=edit_text,
    inputs=gr.Textbox(label="Enter a sentence to edit:"),
    outputs=gr.Textbox(label="Edited sentence:"),
    title="CoEdIT Text Editor",
    description="Edit text using the CoEdIT-xl model.",
)

if __name__ == "__main__":
    iface.launch()