Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -6,7 +6,7 @@ import subprocess
|
|
6 |
import nltk
|
7 |
from nltk.corpus import wordnet
|
8 |
from gensim import downloader as api
|
9 |
-
|
10 |
|
11 |
# Ensure necessary NLTK data is downloaded
|
12 |
nltk.download('wordnet')
|
@@ -29,8 +29,8 @@ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
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
|
33 |
-
|
34 |
|
35 |
# AI detection function using DistilBERT
|
36 |
def detect_ai_generated(text):
|
@@ -123,10 +123,11 @@ def paraphrase_with_spacy_nltk(text):
|
|
123 |
|
124 |
return corrected_text
|
125 |
|
126 |
-
# Function to correct grammar using
|
127 |
def correct_grammar(text):
|
128 |
-
|
129 |
-
|
|
|
130 |
|
131 |
# Combined function: Paraphrase -> Tense Check -> Capitalization -> Grammar Correction
|
132 |
def paraphrase_and_correct(text):
|
|
|
6 |
import nltk
|
7 |
from nltk.corpus import wordnet
|
8 |
from gensim import downloader as api
|
9 |
+
import language_tool_python # LanguageTool for grammar checking
|
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 LanguageTool for grammar correction (English)
|
33 |
+
tool = language_tool_python.LanguageTool('en-US')
|
34 |
|
35 |
# AI detection function using DistilBERT
|
36 |
def detect_ai_generated(text):
|
|
|
123 |
|
124 |
return corrected_text
|
125 |
|
126 |
+
# Function to correct grammar using LanguageTool
|
127 |
def correct_grammar(text):
|
128 |
+
# Apply grammar and spelling suggestions
|
129 |
+
corrected_text = tool.correct(text)
|
130 |
+
return corrected_text
|
131 |
|
132 |
# Combined function: Paraphrase -> Tense Check -> Capitalization -> Grammar Correction
|
133 |
def paraphrase_and_correct(text):
|