sashtech commited on
Commit
6d0ac04
·
verified ·
1 Parent(s): e6cd790

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -18
app.py CHANGED
@@ -5,6 +5,19 @@ import spacy
5
  import subprocess
6
  import nltk
7
  from nltk.corpus import wordnet
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
  # Initialize the English text classification pipeline for AI detection
10
  pipeline_en = pipeline(task="text-classification", model="Hello-SimpleAI/chatgpt-detector-roberta")
@@ -52,18 +65,14 @@ def capitalize_sentences_and_nouns(text):
52
  return ' '.join(corrected_text)
53
 
54
  # Function to correct tense errors in a sentence (Tense Correction)
55
- def correct_tense_errors(text):
56
- doc = nlp(text)
57
- corrected_text = []
58
- for token in doc:
59
- # Check for tense correction based on modal verbs
60
- if token.pos_ == "VERB" and token.dep_ in {"aux", "auxpass"}:
61
- # Replace with appropriate verb form
62
- lemma = wordnet.morphy(token.text, wordnet.VERB) or token.text
63
- corrected_text.append(lemma)
64
- else:
65
- corrected_text.append(token.text)
66
- return ' '.join(corrected_text)
67
 
68
  # Function to correct singular/plural errors (Singular/Plural Correction)
69
  def correct_singular_plural_errors(text):
@@ -141,18 +150,17 @@ def paraphrase_with_spacy_nltk(text):
141
 
142
  # Combined function: Paraphrase -> Grammar Correction -> Capitalization (Humanifier)
143
  def paraphrase_and_correct(text):
144
- # Step 1: Paraphrase the text
145
- paraphrased_text = paraphrase_with_spacy_nltk(text)
146
 
147
  # Step 2: Apply grammatical corrections on the paraphrased text
148
  corrected_text = correct_article_errors(paraphrased_text)
149
 
150
- corrected_text = capitalize_sentences_and_nouns(corrected_text)
 
151
 
 
152
  corrected_text = correct_singular_plural_errors(corrected_text)
153
-
154
- # Step 3: Capitalize sentences and proper nouns (final correction step)
155
- final_text = correct_tense_errors(corrected_text)
156
 
157
  return final_text
158
 
 
5
  import subprocess
6
  import nltk
7
  from nltk.corpus import wordnet
8
+ import language_tool_python
9
+ tool = language_tool_python.LanguageTool('en-US')
10
+
11
+ # Function to correct tense errors using LanguageTool
12
+ def correct_tense_errors(text):
13
+ # Check for grammar mistakes, which includes tense errors
14
+ matches = tool.check(text)
15
+ corrected_text = language_tool_python.utils.correct(text, matches)
16
+ return corrected_text
17
+
18
+
19
+
20
+
21
 
22
  # Initialize the English text classification pipeline for AI detection
23
  pipeline_en = pipeline(task="text-classification", model="Hello-SimpleAI/chatgpt-detector-roberta")
 
65
  return ' '.join(corrected_text)
66
 
67
  # Function to correct tense errors in a sentence (Tense Correction)
68
+ #def correct_tense_errors(text):
69
+ # doc = nlp(text)
70
+ ### if token.pos_ == "VERB" and token.dep_ in {"aux", "auxpass"}:
71
+ ## lemma = wordnet.morphy(token.text, wordnet.VERB) or token.text
72
+ # corrected_text.append(lemma)
73
+ # else:
74
+ # corrected_text.append(token.text)
75
+ # return ' '.join(corrected_text)
 
 
 
 
76
 
77
  # Function to correct singular/plural errors (Singular/Plural Correction)
78
  def correct_singular_plural_errors(text):
 
150
 
151
  # Combined function: Paraphrase -> Grammar Correction -> Capitalization (Humanifier)
152
  def paraphrase_and_correct(text):
153
+ paraphrased_text = paraphrase_with_spacy_nltk(text)
 
154
 
155
  # Step 2: Apply grammatical corrections on the paraphrased text
156
  corrected_text = correct_article_errors(paraphrased_text)
157
 
158
+ # Use the new stronger tense correction method
159
+ corrected_text = correct_tense_errors(corrected_text)
160
 
161
+ # Step 3: Correct singular/plural issues and capitalization
162
  corrected_text = correct_singular_plural_errors(corrected_text)
163
+ final_text = capitalize_sentences_and_nouns(corrected_text)
 
 
164
 
165
  return final_text
166