sashtech commited on
Commit
7e4465c
·
verified ·
1 Parent(s): 7d71609

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -8
app.py CHANGED
@@ -1,11 +1,12 @@
1
  import gradio as gr
2
- from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
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="pszemraj/flan-t5-large-grammar-synthesis", 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)
@@ -48,7 +46,7 @@ def get_synonyms_nltk(word, pos):
48
  return [lemma.name() for lemma in lemmas]
49
  return []
50
 
51
- # Paraphrasing function using spaCy and NLTK
52
  def paraphrase_with_spacy_nltk(text):
53
  doc = nlp(text)
54
  paraphrased_words = []
@@ -78,10 +76,11 @@ def paraphrase_with_spacy_nltk(text):
78
 
79
  return paraphrased_sentence
80
 
81
- # Grammar correction function using FLAN-T5
82
  def correct_grammar(text):
83
- corrected_text = grammar_corrector(text)[0]['generated_text']
84
- return corrected_text
 
85
 
86
  # Combined function: Paraphrase -> Grammar Check
87
  def paraphrase_and_correct(text):
 
1
  import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
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)
 
46
  return [lemma.name() for lemma in lemmas]
47
  return []
48
 
49
+ # Paraphrasing function using spaCy and NLTK (without grammar correction)
50
  def paraphrase_with_spacy_nltk(text):
51
  doc = nlp(text)
52
  paraphrased_words = []
 
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):