Spaces:
				
			
			
	
			
			
					
		Running
		
	
	
	
			
			
	
	
	
	
		
		
					
		Running
		
	Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | @@ -5,7 +5,7 @@ import spacy | |
| 5 | 
             
            import subprocess
         | 
| 6 | 
             
            import nltk
         | 
| 7 | 
             
            from nltk.corpus import wordnet
         | 
| 8 | 
            -
            import  | 
| 9 |  | 
| 10 | 
             
            from gensim import downloader as api
         | 
| 11 |  | 
| @@ -30,8 +30,11 @@ device = torch.device("cuda" if torch.cuda.is_available() else "cpu") | |
| 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  | 
| 34 | 
            -
             | 
|  | |
|  | |
|  | |
| 35 |  | 
| 36 | 
             
            # AI detection function using DistilBERT
         | 
| 37 | 
             
            def detect_ai_generated(text):
         | 
| @@ -50,7 +53,7 @@ def get_synonyms_nltk(word, pos): | |
| 50 | 
             
                    return [lemma.name() for lemma in lemmas]
         | 
| 51 | 
             
                return []
         | 
| 52 |  | 
| 53 | 
            -
            # Paraphrasing function using spaCy and NLTK
         | 
| 54 | 
             
            def paraphrase_with_spacy_nltk(text):
         | 
| 55 | 
             
                doc = nlp(text)
         | 
| 56 | 
             
                paraphrased_words = []
         | 
| @@ -78,8 +81,8 @@ def paraphrase_with_spacy_nltk(text): | |
| 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 =  | 
| 83 |  | 
| 84 | 
             
                return corrected_sentence
         | 
| 85 |  | 
|  | |
| 5 | 
             
            import subprocess
         | 
| 6 | 
             
            import nltk
         | 
| 7 | 
             
            from nltk.corpus import wordnet
         | 
| 8 | 
            +
            from gingerit.gingerit import GingerIt
         | 
| 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 Gingerit for grammar correction
         | 
| 34 | 
            +
            def correct_grammar_with_gingerit(text):
         | 
| 35 | 
            +
                parser = GingerIt()
         | 
| 36 | 
            +
                result = parser.parse(text)
         | 
| 37 | 
            +
                return result['result']
         | 
| 38 |  | 
| 39 | 
             
            # AI detection function using DistilBERT
         | 
| 40 | 
             
            def detect_ai_generated(text):
         | 
|  | |
| 53 | 
             
                    return [lemma.name() for lemma in lemmas]
         | 
| 54 | 
             
                return []
         | 
| 55 |  | 
| 56 | 
            +
            # Paraphrasing function using spaCy and NLTK with Gingerit grammar correction
         | 
| 57 | 
             
            def paraphrase_with_spacy_nltk(text):
         | 
| 58 | 
             
                doc = nlp(text)
         | 
| 59 | 
             
                paraphrased_words = []
         | 
|  | |
| 81 | 
             
                # Join the words back into a sentence
         | 
| 82 | 
             
                paraphrased_sentence = ' '.join(paraphrased_words)
         | 
| 83 |  | 
| 84 | 
            +
                # Correct the grammar of the paraphrased sentence using Gingerit
         | 
| 85 | 
            +
                corrected_sentence = correct_grammar_with_gingerit(paraphrased_sentence)
         | 
| 86 |  | 
| 87 | 
             
                return corrected_sentence
         | 
| 88 |  | 
