Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -9,11 +9,6 @@ from nltk.corpus import wordnet
|
|
9 |
# Initialize the English text classification pipeline for AI detection
|
10 |
pipeline_en = pipeline(task="text-classification", model="Hello-SimpleAI/chatgpt-detector-roberta")
|
11 |
|
12 |
-
# Function to predict the label and score for English text (AI Detection)
|
13 |
-
def predict_en(text):
|
14 |
-
res = pipeline_en(text)[0]
|
15 |
-
return res['label'], res['score']
|
16 |
-
|
17 |
# Ensure necessary NLTK data is downloaded for Humanifier
|
18 |
nltk.download('wordnet')
|
19 |
nltk.download('omw-1.4')
|
@@ -109,8 +104,21 @@ def correct_article_errors(text):
|
|
109 |
|
110 |
# Function to paraphrase and correct grammar
|
111 |
def paraphrase_and_correct(text):
|
112 |
-
|
113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
# Apply grammatical corrections
|
115 |
paraphrased_text = correct_article_errors(paraphrased_text)
|
116 |
paraphrased_text = correct_singular_plural_errors(paraphrased_text)
|
|
|
9 |
# Initialize the English text classification pipeline for AI detection
|
10 |
pipeline_en = pipeline(task="text-classification", model="Hello-SimpleAI/chatgpt-detector-roberta")
|
11 |
|
|
|
|
|
|
|
|
|
|
|
12 |
# Ensure necessary NLTK data is downloaded for Humanifier
|
13 |
nltk.download('wordnet')
|
14 |
nltk.download('omw-1.4')
|
|
|
104 |
|
105 |
# Function to paraphrase and correct grammar
|
106 |
def paraphrase_and_correct(text):
|
107 |
+
# Enhance rephrasing by using more advanced SpaCy functionalities
|
108 |
+
paraphrased_text = capitalize_sentences_and_nouns(text) # Start by capitalizing sentences properly
|
109 |
+
|
110 |
+
# Use SpaCy to rephrase by substituting synonyms, restructuring sentences, etc.
|
111 |
+
doc = nlp(paraphrased_text)
|
112 |
+
rephrased = []
|
113 |
+
for token in doc:
|
114 |
+
synonyms = get_synonyms_nltk(token.text, pos=wordnet.VERB if token.pos_ == "VERB" else wordnet.NOUN)
|
115 |
+
if synonyms:
|
116 |
+
rephrased.append(synonyms[0])
|
117 |
+
else:
|
118 |
+
rephrased.append(token.text)
|
119 |
+
|
120 |
+
paraphrased_text = ' '.join(rephrased)
|
121 |
+
|
122 |
# Apply grammatical corrections
|
123 |
paraphrased_text = correct_article_errors(paraphrased_text)
|
124 |
paraphrased_text = correct_singular_plural_errors(paraphrased_text)
|