Gustav0-Freind
commited on
Commit
•
e4d8732
1
Parent(s):
8976d20
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, T5ForConditionalGeneration
|
3 |
+
|
4 |
+
# Load the CoEdIT-xl model and tokenizer
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained("grammarly/coedit-xl")
|
6 |
+
model = T5ForConditionalGeneration.from_pretrained("grammarly/coedit-xl")
|
7 |
+
|
8 |
+
def edit_text(input_text):
|
9 |
+
# Tokenize input text
|
10 |
+
input_ids = tokenizer(input_text, return_tensors="pt").input_ids
|
11 |
+
# Generate edited text
|
12 |
+
outputs = model.generate(input_ids, max_length=256)
|
13 |
+
edited_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
14 |
+
return edited_text
|
15 |
+
|
16 |
+
# Create a Gradio interface
|
17 |
+
iface = 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 |
+
|
25 |
+
if __name__ == "__main__":
|
26 |
+
iface.launch()
|