Spaces:
Running
Running
ali
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -10,17 +10,20 @@ import string
|
|
10 |
nltk.download('punkt')
|
11 |
nltk.download('stopwords')
|
12 |
|
|
|
|
|
|
|
13 |
# Load AI Detector model and tokenizer from Hugging Face (DistilBERT)
|
14 |
tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english")
|
15 |
-
model = AutoModelForSequenceClassification.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english")
|
16 |
|
17 |
# Load SRDdev Paraphrase model and tokenizer for humanizing text
|
18 |
paraphrase_tokenizer = T5Tokenizer.from_pretrained("SRDdev/Paraphrase")
|
19 |
-
paraphrase_model = T5ForConditionalGeneration.from_pretrained("SRDdev/Paraphrase")
|
20 |
|
21 |
# AI detection function using DistilBERT
|
22 |
def detect_ai_generated(text):
|
23 |
-
inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=512)
|
24 |
with torch.no_grad():
|
25 |
outputs = model(**inputs)
|
26 |
probabilities = torch.softmax(outputs.logits, dim=1)
|
@@ -98,7 +101,7 @@ def humanize_text(AI_text):
|
|
98 |
paraphrased_paragraphs = []
|
99 |
for paragraph in paragraphs:
|
100 |
if paragraph.strip():
|
101 |
-
inputs = paraphrase_tokenizer(paragraph, return_tensors="pt", max_length=512, truncation=True)
|
102 |
paraphrased_ids = paraphrase_model.generate(
|
103 |
inputs['input_ids'],
|
104 |
max_length=inputs['input_ids'].shape[-1] + 20, # Slightly more than the original input length
|
|
|
10 |
nltk.download('punkt')
|
11 |
nltk.download('stopwords')
|
12 |
|
13 |
+
# Check for GPU and set the device accordingly
|
14 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
15 |
+
|
16 |
# Load AI Detector model and tokenizer from Hugging Face (DistilBERT)
|
17 |
tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english")
|
18 |
+
model = AutoModelForSequenceClassification.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english").to(device)
|
19 |
|
20 |
# Load SRDdev Paraphrase model and tokenizer for humanizing text
|
21 |
paraphrase_tokenizer = T5Tokenizer.from_pretrained("SRDdev/Paraphrase")
|
22 |
+
paraphrase_model = T5ForConditionalGeneration.from_pretrained("SRDdev/Paraphrase").to(device)
|
23 |
|
24 |
# AI detection function using DistilBERT
|
25 |
def detect_ai_generated(text):
|
26 |
+
inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=512).to(device)
|
27 |
with torch.no_grad():
|
28 |
outputs = model(**inputs)
|
29 |
probabilities = torch.softmax(outputs.logits, dim=1)
|
|
|
101 |
paraphrased_paragraphs = []
|
102 |
for paragraph in paragraphs:
|
103 |
if paragraph.strip():
|
104 |
+
inputs = paraphrase_tokenizer(paragraph, return_tensors="pt", max_length=512, truncation=True).to(device)
|
105 |
paraphrased_ids = paraphrase_model.generate(
|
106 |
inputs['input_ids'],
|
107 |
max_length=inputs['input_ids'].shape[-1] + 20, # Slightly more than the original input length
|