Spaces:
Sleeping
Sleeping
“[shujaatalishariati]”
commited on
Commit
·
3da716d
1
Parent(s):
41941cd
Added gingerit for grammar correction and updated app.py
Browse files
app.py
CHANGED
@@ -6,6 +6,7 @@ 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,6 +29,9 @@ 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 |
# AI detection function using DistilBERT
|
32 |
def detect_ai_generated(text):
|
33 |
inputs = tokenizer_ai(text, return_tensors="pt", truncation=True, max_length=512).to(device)
|
@@ -96,13 +100,21 @@ def paraphrase_with_spacy_nltk(text):
|
|
96 |
|
97 |
return corrected_text
|
98 |
|
99 |
-
#
|
|
|
|
|
|
|
|
|
|
|
100 |
def paraphrase_and_correct(text):
|
101 |
# Step 1: Paraphrase the text
|
102 |
paraphrased_text = paraphrase_with_spacy_nltk(text)
|
103 |
|
104 |
# Step 2: Capitalize sentences and proper nouns
|
105 |
-
|
|
|
|
|
|
|
106 |
|
107 |
return final_text
|
108 |
|
|
|
6 |
import nltk
|
7 |
from nltk.corpus import wordnet
|
8 |
from gensim import downloader as api
|
9 |
+
from gingerit.gingerit import GingerIt
|
10 |
|
11 |
# Ensure necessary NLTK data is downloaded
|
12 |
nltk.download('wordnet')
|
|
|
29 |
tokenizer_ai = AutoTokenizer.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english")
|
30 |
model_ai = AutoModelForSequenceClassification.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english").to(device)
|
31 |
|
32 |
+
# Initialize GingerIt parser
|
33 |
+
parser = GingerIt()
|
34 |
+
|
35 |
# AI detection function using DistilBERT
|
36 |
def detect_ai_generated(text):
|
37 |
inputs = tokenizer_ai(text, return_tensors="pt", truncation=True, max_length=512).to(device)
|
|
|
100 |
|
101 |
return corrected_text
|
102 |
|
103 |
+
# Function to correct grammar using GingerIt
|
104 |
+
def correct_grammar(text):
|
105 |
+
result = parser.parse(text)
|
106 |
+
return result['result']
|
107 |
+
|
108 |
+
# Combined function: Paraphrase -> Capitalization -> Grammar Correction
|
109 |
def paraphrase_and_correct(text):
|
110 |
# Step 1: Paraphrase the text
|
111 |
paraphrased_text = paraphrase_with_spacy_nltk(text)
|
112 |
|
113 |
# Step 2: Capitalize sentences and proper nouns
|
114 |
+
capitalized_text = capitalize_sentences_and_nouns(paraphrased_text)
|
115 |
+
|
116 |
+
# Step 3: Correct grammar
|
117 |
+
final_text = correct_grammar(capitalized_text)
|
118 |
|
119 |
return final_text
|
120 |
|