Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,7 @@ 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")
|
@@ -25,6 +26,20 @@ 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 (Humanifier)
|
29 |
def get_synonyms_nltk(word, pos):
|
30 |
synsets = wordnet.synsets(word, pos=pos)
|
@@ -94,7 +109,7 @@ def paraphrase_and_correct(text):
|
|
94 |
|
95 |
return final_text
|
96 |
|
97 |
-
# Gradio app setup with
|
98 |
with gr.Blocks() as demo:
|
99 |
with gr.Tab("AI Detection"):
|
100 |
t1 = gr.Textbox(lines=5, label='Text')
|
@@ -112,6 +127,14 @@ with gr.Blocks() as demo:
|
|
112 |
|
113 |
# Connect the paraphrasing function to the button
|
114 |
paraphrase_button.click(paraphrase_and_correct, inputs=text_input, outputs=output_text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
|
116 |
-
# Launch the app with
|
117 |
demo.launch()
|
|
|
5 |
import subprocess
|
6 |
import nltk
|
7 |
from nltk.corpus import wordnet
|
8 |
+
from gector.gec_model import GecBERTModel
|
9 |
|
10 |
# Initialize the English text classification pipeline for AI detection
|
11 |
pipeline_en = pipeline(task="text-classification", model="Hello-SimpleAI/chatgpt-detector-roberta")
|
|
|
26 |
subprocess.run(["python", "-m", "spacy", "download", "en_core_web_sm"])
|
27 |
nlp = spacy.load("en_core_web_sm")
|
28 |
|
29 |
+
# Initialize GECToR model for grammar correction
|
30 |
+
gector_model = GecBERTModel(vocab_path='data/output_vocabulary',
|
31 |
+
model_paths=['https://grammarly-nlp-data.s3.amazonaws.com/gector/roberta_1_gector.th'],
|
32 |
+
is_ensemble=False)
|
33 |
+
|
34 |
+
# Function to correct grammar using GECToR
|
35 |
+
def correct_grammar_with_gector(text):
|
36 |
+
corrected_sentences = []
|
37 |
+
sentences = [text] # If you want to split into sentences, you can implement that here
|
38 |
+
for sentence in sentences:
|
39 |
+
preds = gector_model.handle_batch([sentence])
|
40 |
+
corrected_sentences.append(preds[0])
|
41 |
+
return ' '.join(corrected_sentences)
|
42 |
+
|
43 |
# Function to get synonyms using NLTK WordNet (Humanifier)
|
44 |
def get_synonyms_nltk(word, pos):
|
45 |
synsets = wordnet.synsets(word, pos=pos)
|
|
|
109 |
|
110 |
return final_text
|
111 |
|
112 |
+
# Gradio app setup with three tabs
|
113 |
with gr.Blocks() as demo:
|
114 |
with gr.Tab("AI Detection"):
|
115 |
t1 = gr.Textbox(lines=5, label='Text')
|
|
|
127 |
|
128 |
# Connect the paraphrasing function to the button
|
129 |
paraphrase_button.click(paraphrase_and_correct, inputs=text_input, outputs=output_text)
|
130 |
+
|
131 |
+
with gr.Tab("Grammar Correction"):
|
132 |
+
grammar_input = gr.Textbox(lines=5, label="Input Text")
|
133 |
+
grammar_button = gr.Button("Correct Grammar")
|
134 |
+
grammar_output = gr.Textbox(label="Corrected Text")
|
135 |
+
|
136 |
+
# Connect the GECToR grammar correction function to the button
|
137 |
+
grammar_button.click(correct_grammar_with_gector, inputs=grammar_input, outputs=grammar_output)
|
138 |
|
139 |
+
# Launch the app with all functionalities
|
140 |
demo.launch()
|