Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Import libraries
|
2 |
+
from transformers import T5Tokenizer, T5ForConditionalGeneration
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
# Load a pre-trained T5 model specifically fine-tuned for grammar correction
|
6 |
+
tokenizer = T5Tokenizer.from_pretrained("prithivida/grammar_error_correcter_v1")
|
7 |
+
model = T5ForConditionalGeneration.from_pretrained("prithivida/grammar_error_correcter_v1")
|
8 |
+
|
9 |
+
# Function to perform grammar correction
|
10 |
+
def grammar_check(text):
|
11 |
+
input_text = f"gec: {text}"
|
12 |
+
input_ids = tokenizer.encode(input_text, return_tensors="pt")
|
13 |
+
outputs = model.generate(input_ids)
|
14 |
+
corrected_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
15 |
+
return corrected_text
|
16 |
+
|
17 |
+
# Create Gradio interface with a writing prompt
|
18 |
+
interface = gr.Interface(
|
19 |
+
fn=grammar_check,
|
20 |
+
inputs="text",
|
21 |
+
outputs="text",
|
22 |
+
title="Grammar Checker",
|
23 |
+
description=(
|
24 |
+
"Enter text to check for grammar mistakes.\n\n"
|
25 |
+
"Writing Prompt:\n"
|
26 |
+
"In the story, Alex and his friends decided to donate all the treasure to the town library. "
|
27 |
+
"This can be a good metaphor for the idea that individuals should sacrifice for society. Some people "
|
28 |
+
"claim that individuals do not have to sacrifice but only think about their own happiness. To what extent "
|
29 |
+
"do you agree or disagree with this?\n\n"
|
30 |
+
"Explain your reasons with some relevant examples from your own experience and knowledge. "
|
31 |
+
"(At least 100 words)"
|
32 |
+
)
|
33 |
+
)
|
34 |
+
|
35 |
+
# Launch the interface
|
36 |
+
interface.launch()
|