Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -24,17 +24,17 @@ word_vectors = api.load("glove-wiki-gigaword-50")
|
|
| 24 |
# Check for GPU and set the device accordingly
|
| 25 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 26 |
|
| 27 |
-
# Load AI Detector model and tokenizer from Hugging Face (
|
| 28 |
-
tokenizer_ai = AutoTokenizer.from_pretrained("
|
| 29 |
-
model_ai = AutoModelForSequenceClassification.from_pretrained("
|
| 30 |
|
| 31 |
-
# AI detection function using
|
| 32 |
def detect_ai_generated(text):
|
| 33 |
inputs = tokenizer_ai(text, return_tensors="pt", truncation=True, max_length=512).to(device)
|
| 34 |
with torch.no_grad():
|
| 35 |
outputs = model_ai(**inputs)
|
| 36 |
probabilities = torch.softmax(outputs.logits, dim=1)
|
| 37 |
-
ai_probability = probabilities[0][1].item() # Probability of being AI-generated
|
| 38 |
return f"AI-Generated Content Probability: {ai_probability:.2f}%"
|
| 39 |
|
| 40 |
# Function to get synonyms using NLTK WordNet
|
|
|
|
| 24 |
# Check for GPU and set the device accordingly
|
| 25 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 26 |
|
| 27 |
+
# Load AI Detector model and tokenizer from Hugging Face (roberta-base-openai-detector)
|
| 28 |
+
tokenizer_ai = AutoTokenizer.from_pretrained("roberta-base-openai-detector")
|
| 29 |
+
model_ai = AutoModelForSequenceClassification.from_pretrained("roberta-base-openai-detector").to(device)
|
| 30 |
|
| 31 |
+
# AI detection function using RoBERTa-based model
|
| 32 |
def detect_ai_generated(text):
|
| 33 |
inputs = tokenizer_ai(text, return_tensors="pt", truncation=True, max_length=512).to(device)
|
| 34 |
with torch.no_grad():
|
| 35 |
outputs = model_ai(**inputs)
|
| 36 |
probabilities = torch.softmax(outputs.logits, dim=1)
|
| 37 |
+
ai_probability = probabilities[0][1].item() * 100 # Probability of being AI-generated
|
| 38 |
return f"AI-Generated Content Probability: {ai_probability:.2f}%"
|
| 39 |
|
| 40 |
# Function to get synonyms using NLTK WordNet
|