Spaces:
Running
Running
fix2
Browse files
app.py
CHANGED
@@ -6,18 +6,21 @@ import os, glob
|
|
6 |
import spaces
|
7 |
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
8 |
import torch
|
|
|
9 |
model_name = 'hyunseoki/ReMoDetect-deberta'
|
10 |
|
11 |
THESHOLD=4.0
|
12 |
-
predictor = AutoModelForSequenceClassification.from_pretrained(model_name)
|
13 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
|
|
14 |
|
15 |
@spaces.GPU
|
16 |
def predict(text):
|
17 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
18 |
predictor.to(device)
|
19 |
tokenized = tokenizer(text, return_tensors='pt', truncation=True, max_length=512).to(device)
|
20 |
-
|
|
|
21 |
AI_score = round(torch.sigmoid(torch.tensor(result-THESHOLD)*2).item(),2)
|
22 |
return f'{AI_score*100} %', f'{round(result,2)}'
|
23 |
|
|
|
6 |
import spaces
|
7 |
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
8 |
import torch
|
9 |
+
|
10 |
model_name = 'hyunseoki/ReMoDetect-deberta'
|
11 |
|
12 |
THESHOLD=4.0
|
13 |
+
predictor = AutoModelForSequenceClassification.from_pretrained(model_name, force_download=True)
|
14 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
15 |
+
predictor.eval()
|
16 |
|
17 |
@spaces.GPU
|
18 |
def predict(text):
|
19 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
20 |
predictor.to(device)
|
21 |
tokenized = tokenizer(text, return_tensors='pt', truncation=True, max_length=512).to(device)
|
22 |
+
with torch.no_grad():
|
23 |
+
result = predictor(**tokenized).logits[0].cpu().detach().item()
|
24 |
AI_score = round(torch.sigmoid(torch.tensor(result-THESHOLD)*2).item(),2)
|
25 |
return f'{AI_score*100} %', f'{round(result,2)}'
|
26 |
|