Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -25,6 +25,24 @@ except OSError:
|
|
| 25 |
subprocess.run(["python", "-m", "spacy", "download", "en_core_web_sm"])
|
| 26 |
nlp = spacy.load("en_core_web_sm")
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
# Function to get synonyms using NLTK WordNet and keep the same grammatical form
|
| 29 |
def get_synonym(word, pos_tag):
|
| 30 |
synsets = wordnet.synsets(word)
|
|
@@ -85,6 +103,62 @@ def paraphrase_and_correct(text):
|
|
| 85 |
|
| 86 |
return paraphrased_text
|
| 87 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
# Gradio app setup with two tabs
|
| 89 |
with gr.Blocks() as demo:
|
| 90 |
with gr.Tab("AI Detection"):
|
|
@@ -105,4 +179,4 @@ with gr.Blocks() as demo:
|
|
| 105 |
paraphrase_button.click(paraphrase_and_correct, inputs=text_input, outputs=output_text)
|
| 106 |
|
| 107 |
# Launch the app with the remaining functionalities
|
| 108 |
-
demo.launch()
|
|
|
|
| 25 |
subprocess.run(["python", "-m", "spacy", "download", "en_core_web_sm"])
|
| 26 |
nlp = spacy.load("en_core_web_sm")
|
| 27 |
|
| 28 |
+
# Function to capitalize the first letter of sentences and proper nouns (Humanifier)
|
| 29 |
+
def capitalize_sentences_and_nouns(text):
|
| 30 |
+
doc = nlp(text)
|
| 31 |
+
corrected_text = []
|
| 32 |
+
|
| 33 |
+
for sent in doc.sents:
|
| 34 |
+
sentence = []
|
| 35 |
+
for token in sent:
|
| 36 |
+
if token.i == sent.start: # First word of the sentence
|
| 37 |
+
sentence.append(token.text.capitalize())
|
| 38 |
+
elif token.pos_ == "PROPN": # Proper noun
|
| 39 |
+
sentence.append(token.text.capitalize())
|
| 40 |
+
else:
|
| 41 |
+
sentence.append(token.text)
|
| 42 |
+
corrected_text.append(' '.join(sentence))
|
| 43 |
+
|
| 44 |
+
return ' '.join(corrected_text)
|
| 45 |
+
|
| 46 |
# Function to get synonyms using NLTK WordNet and keep the same grammatical form
|
| 47 |
def get_synonym(word, pos_tag):
|
| 48 |
synsets = wordnet.synsets(word)
|
|
|
|
| 103 |
|
| 104 |
return paraphrased_text
|
| 105 |
|
| 106 |
+
# Function to correct tense errors in a sentence (Tense Correction)
|
| 107 |
+
def correct_tense_errors(text):
|
| 108 |
+
doc = nlp(text)
|
| 109 |
+
corrected_text = []
|
| 110 |
+
for token in doc:
|
| 111 |
+
# Check for tense correction based on modal verbs
|
| 112 |
+
if token.pos_ == "VERB" and token.dep_ in {"aux", "auxpass"}:
|
| 113 |
+
# Replace with appropriate verb form
|
| 114 |
+
lemma = wordnet.morphy(token.text, wordnet.VERB) or token.text
|
| 115 |
+
corrected_text.append(lemma)
|
| 116 |
+
else:
|
| 117 |
+
corrected_text.append(token.text)
|
| 118 |
+
return ' '.join(corrected_text)
|
| 119 |
+
|
| 120 |
+
# Function to correct singular/plural errors (Singular/Plural Correction)
|
| 121 |
+
def correct_singular_plural_errors(text):
|
| 122 |
+
doc = nlp(text)
|
| 123 |
+
corrected_text = []
|
| 124 |
+
|
| 125 |
+
for token in doc:
|
| 126 |
+
if token.pos_ == "NOUN":
|
| 127 |
+
# Check if the noun is singular or plural
|
| 128 |
+
if token.tag_ == "NN": # Singular noun
|
| 129 |
+
# Look for determiners like "many", "several", "few" to correct to plural
|
| 130 |
+
if any(child.text.lower() in ['many', 'several', 'few'] for child in token.head.children):
|
| 131 |
+
corrected_text.append(token.lemma_ + 's')
|
| 132 |
+
else:
|
| 133 |
+
corrected_text.append(token.text)
|
| 134 |
+
elif token.tag_ == "NNS": # Plural noun
|
| 135 |
+
# Look for determiners like "a", "one" to correct to singular
|
| 136 |
+
if any(child.text.lower() in ['a', 'one'] for child in token.head.children):
|
| 137 |
+
corrected_text.append(token.lemma_)
|
| 138 |
+
else:
|
| 139 |
+
corrected_text.append(token.text)
|
| 140 |
+
else:
|
| 141 |
+
corrected_text.append(token.text)
|
| 142 |
+
|
| 143 |
+
return ' '.join(corrected_text)
|
| 144 |
+
|
| 145 |
+
# Function to check and correct article errors
|
| 146 |
+
def correct_article_errors(text):
|
| 147 |
+
doc = nlp(text)
|
| 148 |
+
corrected_text = []
|
| 149 |
+
for token in doc:
|
| 150 |
+
if token.text in ['a', 'an']:
|
| 151 |
+
next_token = token.nbor(1)
|
| 152 |
+
if token.text == "a" and next_token.text[0].lower() in "aeiou":
|
| 153 |
+
corrected_text.append("an")
|
| 154 |
+
elif token.text == "an" and next_token.text[0].lower() not in "aeiou":
|
| 155 |
+
corrected_text.append("a")
|
| 156 |
+
else:
|
| 157 |
+
corrected_text.append(token.text)
|
| 158 |
+
else:
|
| 159 |
+
corrected_text.append(token.text)
|
| 160 |
+
return ' '.join(corrected_text)
|
| 161 |
+
|
| 162 |
# Gradio app setup with two tabs
|
| 163 |
with gr.Blocks() as demo:
|
| 164 |
with gr.Tab("AI Detection"):
|
|
|
|
| 179 |
paraphrase_button.click(paraphrase_and_correct, inputs=text_input, outputs=output_text)
|
| 180 |
|
| 181 |
# Launch the app with the remaining functionalities
|
| 182 |
+
demo.launch(share=True)
|