Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,13 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import AutoTokenizer,
|
3 |
import torch
|
4 |
import spacy
|
5 |
import subprocess
|
6 |
import nltk
|
7 |
from nltk.corpus import wordnet
|
8 |
from gensim import downloader as api
|
|
|
|
|
9 |
|
10 |
# Ensure necessary NLTK data is downloaded
|
11 |
nltk.download('wordnet')
|
@@ -28,9 +30,11 @@ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
28 |
tokenizer_ai = AutoTokenizer.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english")
|
29 |
model_ai = AutoModelForSequenceClassification.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english").to(device)
|
30 |
|
31 |
-
#
|
32 |
-
|
33 |
-
|
|
|
|
|
34 |
|
35 |
# AI detection function using DistilBERT
|
36 |
def detect_ai_generated(text):
|
@@ -123,14 +127,17 @@ def paraphrase_with_spacy_nltk(text):
|
|
123 |
|
124 |
return corrected_text
|
125 |
|
126 |
-
# Function to correct
|
127 |
-
def
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
|
|
|
|
|
|
132 |
|
133 |
-
# Combined function: Paraphrase -> Tense Check -> Capitalization -> Grammar Correction
|
134 |
def paraphrase_and_correct(text):
|
135 |
# Step 1: Paraphrase the text
|
136 |
paraphrased_text = paraphrase_with_spacy_nltk(text)
|
@@ -141,8 +148,8 @@ def paraphrase_and_correct(text):
|
|
141 |
# Step 3: Capitalize sentences and proper nouns
|
142 |
capitalized_text = capitalize_sentences_and_nouns(tense_checked_text)
|
143 |
|
144 |
-
# Step 4: Correct
|
145 |
-
final_text =
|
146 |
|
147 |
return final_text
|
148 |
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
3 |
import torch
|
4 |
import spacy
|
5 |
import subprocess
|
6 |
import nltk
|
7 |
from nltk.corpus import wordnet
|
8 |
from gensim import downloader as api
|
9 |
+
from autocorrect import Speller # Autocorrect library for spelling correction
|
10 |
+
from gingerit.gingerit import GingerIt # GingerIt for grammar correction
|
11 |
|
12 |
# Ensure necessary NLTK data is downloaded
|
13 |
nltk.download('wordnet')
|
|
|
30 |
tokenizer_ai = AutoTokenizer.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english")
|
31 |
model_ai = AutoModelForSequenceClassification.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english").to(device)
|
32 |
|
33 |
+
# Initialize Autocorrect for spelling correction
|
34 |
+
spell = Speller()
|
35 |
+
|
36 |
+
# Initialize GingerIt for grammar correction
|
37 |
+
parser = GingerIt()
|
38 |
|
39 |
# AI detection function using DistilBERT
|
40 |
def detect_ai_generated(text):
|
|
|
127 |
|
128 |
return corrected_text
|
129 |
|
130 |
+
# Function to correct spelling using autocorrect and grammar using GingerIt
|
131 |
+
def correct_spelling_and_grammar(text):
|
132 |
+
# Step 1: Correct spelling using autocorrect
|
133 |
+
corrected_spelling = spell(text)
|
134 |
+
|
135 |
+
# Step 2: Correct grammar using GingerIt
|
136 |
+
grammar_correction = parser.parse(corrected_spelling)
|
137 |
+
|
138 |
+
return grammar_correction['result']
|
139 |
|
140 |
+
# Combined function: Paraphrase -> Tense Check -> Capitalization -> Spelling and Grammar Correction
|
141 |
def paraphrase_and_correct(text):
|
142 |
# Step 1: Paraphrase the text
|
143 |
paraphrased_text = paraphrase_with_spacy_nltk(text)
|
|
|
148 |
# Step 3: Capitalize sentences and proper nouns
|
149 |
capitalized_text = capitalize_sentences_and_nouns(tense_checked_text)
|
150 |
|
151 |
+
# Step 4: Correct spelling and grammar
|
152 |
+
final_text = correct_spelling_and_grammar(capitalized_text)
|
153 |
|
154 |
return final_text
|
155 |
|