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 |
from gensim import downloader as api
|
10 |
|
@@ -29,6 +30,9 @@ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
29 |
tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english")
|
30 |
model = AutoModelForSequenceClassification.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english").to(device)
|
31 |
|
|
|
|
|
|
|
32 |
# AI detection function using DistilBERT
|
33 |
def detect_ai_generated(text):
|
34 |
inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=512).to(device)
|
@@ -73,7 +77,11 @@ def paraphrase_with_spacy_nltk(text):
|
|
73 |
|
74 |
# Join the words back into a sentence
|
75 |
paraphrased_sentence = ' '.join(paraphrased_words)
|
76 |
-
|
|
|
|
|
|
|
|
|
77 |
|
78 |
# Gradio interface definition
|
79 |
with gr.Blocks() as interface:
|
@@ -81,7 +89,7 @@ with gr.Blocks() as interface:
|
|
81 |
with gr.Column():
|
82 |
text_input = gr.Textbox(lines=5, label="Input Text")
|
83 |
detect_button = gr.Button("AI Detection")
|
84 |
-
paraphrase_button = gr.Button("Paraphrase with spaCy & NLTK")
|
85 |
with gr.Column():
|
86 |
output_text = gr.Textbox(label="Output")
|
87 |
|
|
|
5 |
import subprocess
|
6 |
import nltk
|
7 |
from nltk.corpus import wordnet
|
8 |
+
import language_tool_python
|
9 |
|
10 |
from gensim import downloader as api
|
11 |
|
|
|
30 |
tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english")
|
31 |
model = AutoModelForSequenceClassification.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english").to(device)
|
32 |
|
33 |
+
# Initialize LanguageTool for grammar correction
|
34 |
+
tool = language_tool_python.LanguageTool('en-US')
|
35 |
+
|
36 |
# AI detection function using DistilBERT
|
37 |
def detect_ai_generated(text):
|
38 |
inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=512).to(device)
|
|
|
77 |
|
78 |
# Join the words back into a sentence
|
79 |
paraphrased_sentence = ' '.join(paraphrased_words)
|
80 |
+
|
81 |
+
# Correct the grammar of the paraphrased sentence
|
82 |
+
corrected_sentence = tool.correct(paraphrased_sentence)
|
83 |
+
|
84 |
+
return corrected_sentence
|
85 |
|
86 |
# Gradio interface definition
|
87 |
with gr.Blocks() as interface:
|
|
|
89 |
with gr.Column():
|
90 |
text_input = gr.Textbox(lines=5, label="Input Text")
|
91 |
detect_button = gr.Button("AI Detection")
|
92 |
+
paraphrase_button = gr.Button("Paraphrase with spaCy & NLTK (Grammar Corrected)")
|
93 |
with gr.Column():
|
94 |
output_text = gr.Textbox(label="Output")
|
95 |
|