dentadelta123 commited on
Commit
b7f2a4b
1 Parent(s): 8bcb7c8
Files changed (2) hide show
  1. app.py +35 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import T5Tokenizer, T5ForConditionalGeneration
2
+ import torch
3
+ import gradio as gr
4
+
5
+ device = 'cuda' if torch.cuda.is_available() else 'cpu'
6
+ model = T5ForConditionalGeneration.from_pretrained("vennify/t5-base-grammar-correction")
7
+ tokenizer = T5Tokenizer.from_pretrained("vennify/t5-base-grammar-correction")
8
+ model.to(device)
9
+ model.eval()
10
+
11
+
12
+ def generate_text(text):
13
+ text = f'grammar: {text}'
14
+ input_ids = tokenizer(
15
+ text, return_tensors="pt"
16
+ ).input_ids
17
+ input_ids = input_ids.to(device)
18
+
19
+ outputs = model.generate(input_ids)
20
+
21
+ return tokenizer.decode(outputs[0], skip_special_tokens=True)
22
+
23
+
24
+ with gr.Blocks() as deeplearning:
25
+ with gr.Row():
26
+ with gr.Column():
27
+ text = gr.inputs.Textbox(lines=10, placeholder="Enter your text here...")
28
+ button = gr.Button(label="Correct")
29
+ output = gr.outputs.Textbox(label="Corrected Text")
30
+
31
+
32
+ button.click(generate_text, inputs=text, outputs=output)
33
+
34
+
35
+ deeplearning.launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ transformers
2
+ torch