Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -22,12 +22,8 @@ inflect_engine = inflect.engine()
|
|
| 22 |
nltk.download('wordnet')
|
| 23 |
nltk.download('omw-1.4')
|
| 24 |
|
| 25 |
-
#
|
| 26 |
-
|
| 27 |
-
nlp = spacy.load("en_core_web_sm")
|
| 28 |
-
except OSError:
|
| 29 |
-
subprocess.run(["python", "-m", "spacy", "download", "en_core_web_sm"])
|
| 30 |
-
nlp = spacy.load("en_core_web_sm")
|
| 31 |
|
| 32 |
# Function to predict the label and score for English text (AI Detection)
|
| 33 |
def predict_en(text):
|
|
@@ -173,18 +169,18 @@ def correct_spelling(text):
|
|
| 173 |
corrected_words = []
|
| 174 |
for word in words:
|
| 175 |
corrected_word = spell.correction(word)
|
| 176 |
-
corrected_words.append(corrected_word if corrected_word else word)
|
| 177 |
return ' '.join(corrected_words)
|
| 178 |
|
| 179 |
# Function to correct punctuation issues
|
| 180 |
def correct_punctuation(text):
|
| 181 |
-
text = re.sub(r'\s+([?.!,";:])', r'\1', text)
|
| 182 |
-
text = re.sub(r'([?.!,";:])\s+', r'\1 ', text)
|
| 183 |
return text
|
| 184 |
|
| 185 |
# Function to ensure correct handling of possessive forms
|
| 186 |
def handle_possessives(text):
|
| 187 |
-
text = re.sub(r"\b(\w+)'s\b", r"\1's", text)
|
| 188 |
return text
|
| 189 |
|
| 190 |
# Function to rephrase text and replace words with their synonyms while maintaining form
|
|
@@ -231,37 +227,37 @@ def paraphrase_and_correct(text):
|
|
| 231 |
# Remove meaningless or redundant words first
|
| 232 |
cleaned_text = remove_redundant_words(text)
|
| 233 |
|
| 234 |
-
# Capitalize sentences and nouns
|
| 235 |
-
|
| 236 |
-
|
| 237 |
# Correct tense errors
|
| 238 |
-
|
| 239 |
-
|
| 240 |
# Correct singular/plural errors
|
| 241 |
-
|
| 242 |
-
|
| 243 |
# Correct article errors
|
| 244 |
-
|
| 245 |
-
|
| 246 |
# Correct spelling
|
| 247 |
-
|
| 248 |
-
|
| 249 |
# Correct punctuation issues
|
| 250 |
-
|
| 251 |
-
|
| 252 |
# Handle possessives
|
| 253 |
-
|
| 254 |
-
|
| 255 |
# Replace words with synonyms
|
| 256 |
-
|
| 257 |
|
| 258 |
# Correct double negatives
|
| 259 |
-
|
| 260 |
|
| 261 |
# Ensure subject-verb agreement
|
| 262 |
-
|
| 263 |
|
| 264 |
-
return
|
| 265 |
|
| 266 |
# Function to detect AI-generated content
|
| 267 |
def detect_ai(text):
|
|
@@ -277,7 +273,7 @@ def gradio_interface(text):
|
|
| 277 |
# Create Gradio interface
|
| 278 |
iface = gr.Interface(fn=gradio_interface,
|
| 279 |
inputs=gr.Textbox(lines=5, placeholder="Enter text here..."),
|
| 280 |
-
outputs=[gr.
|
| 281 |
title="AI Detection and Grammar Correction",
|
| 282 |
description="Detect AI-generated content and correct grammar issues.")
|
| 283 |
|
|
|
|
| 22 |
nltk.download('wordnet')
|
| 23 |
nltk.download('omw-1.4')
|
| 24 |
|
| 25 |
+
# Load the SpaCy model
|
| 26 |
+
nlp = spacy.load("en_core_web_sm")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
# Function to predict the label and score for English text (AI Detection)
|
| 29 |
def predict_en(text):
|
|
|
|
| 169 |
corrected_words = []
|
| 170 |
for word in words:
|
| 171 |
corrected_word = spell.correction(word)
|
| 172 |
+
corrected_words.append(corrected_word if corrected_word else word)
|
| 173 |
return ' '.join(corrected_words)
|
| 174 |
|
| 175 |
# Function to correct punctuation issues
|
| 176 |
def correct_punctuation(text):
|
| 177 |
+
text = re.sub(r'\s+([?.!,";:])', r'\1', text)
|
| 178 |
+
text = re.sub(r'([?.!,";:])\s+', r'\1 ', text)
|
| 179 |
return text
|
| 180 |
|
| 181 |
# Function to ensure correct handling of possessive forms
|
| 182 |
def handle_possessives(text):
|
| 183 |
+
text = re.sub(r"\b(\w+)'s\b", r"\1's", text)
|
| 184 |
return text
|
| 185 |
|
| 186 |
# Function to rephrase text and replace words with their synonyms while maintaining form
|
|
|
|
| 227 |
# Remove meaningless or redundant words first
|
| 228 |
cleaned_text = remove_redundant_words(text)
|
| 229 |
|
| 230 |
+
# Capitalize sentences and proper nouns
|
| 231 |
+
cleaned_text = capitalize_sentences_and_nouns(cleaned_text)
|
| 232 |
+
|
| 233 |
# Correct tense errors
|
| 234 |
+
cleaned_text = correct_tense_errors(cleaned_text)
|
| 235 |
+
|
| 236 |
# Correct singular/plural errors
|
| 237 |
+
cleaned_text = correct_singular_plural_errors(cleaned_text)
|
| 238 |
+
|
| 239 |
# Correct article errors
|
| 240 |
+
cleaned_text = correct_article_errors(cleaned_text)
|
| 241 |
+
|
| 242 |
# Correct spelling
|
| 243 |
+
cleaned_text = correct_spelling(cleaned_text)
|
| 244 |
+
|
| 245 |
# Correct punctuation issues
|
| 246 |
+
cleaned_text = correct_punctuation(cleaned_text)
|
| 247 |
+
|
| 248 |
# Handle possessives
|
| 249 |
+
cleaned_text = handle_possessives(cleaned_text)
|
| 250 |
+
|
| 251 |
# Replace words with synonyms
|
| 252 |
+
cleaned_text = rephrase_with_synonyms(cleaned_text)
|
| 253 |
|
| 254 |
# Correct double negatives
|
| 255 |
+
cleaned_text = correct_double_negatives(cleaned_text)
|
| 256 |
|
| 257 |
# Ensure subject-verb agreement
|
| 258 |
+
cleaned_text = ensure_subject_verb_agreement(cleaned_text)
|
| 259 |
|
| 260 |
+
return cleaned_text
|
| 261 |
|
| 262 |
# Function to detect AI-generated content
|
| 263 |
def detect_ai(text):
|
|
|
|
| 273 |
# Create Gradio interface
|
| 274 |
iface = gr.Interface(fn=gradio_interface,
|
| 275 |
inputs=gr.Textbox(lines=5, placeholder="Enter text here..."),
|
| 276 |
+
outputs=[gr.Label(num_top_classes=2), gr.Textbox()],
|
| 277 |
title="AI Detection and Grammar Correction",
|
| 278 |
description="Detect AI-generated content and correct grammar issues.")
|
| 279 |
|