sashtech commited on
Commit
463d2eb
·
verified ·
1 Parent(s): ccdad55

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -15
app.py CHANGED
@@ -5,16 +5,6 @@ import spacy
5
  import subprocess
6
  import nltk
7
  from nltk.corpus import wordnet
8
- import language_tool_python
9
-
10
- tool = language_tool_python.LanguageTool('en-US')
11
-
12
- # Function to correct tense errors using LanguageTool
13
- def correct_tense_errors(text):
14
- # Check for grammar mistakes, which includes tense errors
15
- matches = tool.check(text)
16
- corrected_text = language_tool_python.utils.correct(text, matches)
17
- return corrected_text
18
 
19
  # Initialize the English text classification pipeline for AI detection
20
  pipeline_en = pipeline(task="text-classification", model="Hello-SimpleAI/chatgpt-detector-roberta")
@@ -61,6 +51,20 @@ def capitalize_sentences_and_nouns(text):
61
 
62
  return ' '.join(corrected_text)
63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  # Function to correct singular/plural errors (Singular/Plural Correction)
65
  def correct_singular_plural_errors(text):
66
  doc = nlp(text)
@@ -137,17 +141,18 @@ def paraphrase_with_spacy_nltk(text):
137
 
138
  # Combined function: Paraphrase -> Grammar Correction -> Capitalization (Humanifier)
139
  def paraphrase_and_correct(text):
 
140
  paraphrased_text = paraphrase_with_spacy_nltk(text)
141
 
142
  # Step 2: Apply grammatical corrections on the paraphrased text
143
  corrected_text = correct_article_errors(paraphrased_text)
144
 
145
- # Use the new stronger tense correction method
146
- corrected_text = correct_tense_errors(corrected_text)
147
 
148
- # Step 3: Correct singular/plural issues and capitalization
149
  corrected_text = correct_singular_plural_errors(corrected_text)
150
- final_text = capitalize_sentences_and_nouns(corrected_text)
 
 
151
 
152
  return final_text
153
 
@@ -171,4 +176,4 @@ with gr.Blocks() as demo:
171
  paraphrase_button.click(paraphrase_and_correct, inputs=text_input, outputs=output_text)
172
 
173
  # Launch the app with the remaining functionalities
174
- demo.launch()
 
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")
 
51
 
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):
70
  doc = nlp(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
 
 
176
  paraphrase_button.click(paraphrase_and_correct, inputs=text_input, outputs=output_text)
177
 
178
  # Launch the app with the remaining functionalities
179
+ demo.launch()