Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,12 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 3 |
import torch
|
| 4 |
import spacy
|
| 5 |
import subprocess
|
| 6 |
import nltk
|
| 7 |
from nltk.corpus import wordnet
|
| 8 |
from gensim import downloader as api
|
|
|
|
| 9 |
|
| 10 |
# Ensure necessary NLTK data is downloaded
|
| 11 |
nltk.download('wordnet')
|
|
@@ -28,9 +29,6 @@ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
| 28 |
tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english")
|
| 29 |
model = AutoModelForSequenceClassification.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english").to(device)
|
| 30 |
|
| 31 |
-
# Load grammar correction model from Hugging Face
|
| 32 |
-
grammar_corrector = pipeline("text2text-generation", model="prithivida/grammar-error-correction", device=0 if torch.cuda.is_available() else -1)
|
| 33 |
-
|
| 34 |
# AI detection function using DistilBERT
|
| 35 |
def detect_ai_generated(text):
|
| 36 |
inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=512).to(device)
|
|
@@ -78,10 +76,11 @@ def paraphrase_with_spacy_nltk(text):
|
|
| 78 |
|
| 79 |
return paraphrased_sentence
|
| 80 |
|
| 81 |
-
# Grammar correction function using
|
| 82 |
def correct_grammar(text):
|
| 83 |
-
|
| 84 |
-
|
|
|
|
| 85 |
|
| 86 |
# Combined function: Paraphrase -> Grammar Check
|
| 87 |
def paraphrase_and_correct(text):
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 3 |
import torch
|
| 4 |
import spacy
|
| 5 |
import subprocess
|
| 6 |
import nltk
|
| 7 |
from nltk.corpus import wordnet
|
| 8 |
from gensim import downloader as api
|
| 9 |
+
from gingerit.gingerit import GingerIt # Import GingerIt for grammar correction
|
| 10 |
|
| 11 |
# Ensure necessary NLTK data is downloaded
|
| 12 |
nltk.download('wordnet')
|
|
|
|
| 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)
|
|
|
|
| 76 |
|
| 77 |
return paraphrased_sentence
|
| 78 |
|
| 79 |
+
# Grammar correction function using GingerIt
|
| 80 |
def correct_grammar(text):
|
| 81 |
+
parser = GingerIt()
|
| 82 |
+
result = parser.parse(text)
|
| 83 |
+
return result['result'] # Return the corrected text
|
| 84 |
|
| 85 |
# Combined function: Paraphrase -> Grammar Check
|
| 86 |
def paraphrase_and_correct(text):
|