Spaces:
Build error
Build error
changed app.py
Browse files
app.py
CHANGED
|
@@ -4,15 +4,15 @@ from src.model import BertClassifier, RobertaClassifier
|
|
| 4 |
from transformers import BertTokenizer
|
| 5 |
from datetime import datetime
|
| 6 |
|
| 7 |
-
device = torch.device('cpu')
|
| 8 |
|
| 9 |
-
model_name = 'bert-base-uncased'
|
| 10 |
-
model = BertClassifier(model_name, 0.5)
|
| 11 |
-
model.to(device)
|
| 12 |
-
model.load_state_dict(torch.load('models/bert-all-data.pth', map_location=device))
|
| 13 |
-
tokenizer = BertTokenizer.from_pretrained(model_name)
|
| 14 |
|
| 15 |
def ai_text_classifier(text: str):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
tokens = tokenizer(text, return_tensors='pt', max_length=512, padding='max_length', truncation=True).to(device)
|
| 17 |
prob = model(tokens['input_ids'], tokens['attention_mask']).item()
|
| 18 |
|
|
|
|
| 4 |
from transformers import BertTokenizer
|
| 5 |
from datetime import datetime
|
| 6 |
|
|
|
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
def ai_text_classifier(text: str):
|
| 10 |
+
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
| 11 |
+
model_name = 'bert-base-uncased'
|
| 12 |
+
model = BertClassifier(model_name, 0.5)
|
| 13 |
+
model.to(device)
|
| 14 |
+
model.load_state_dict(torch.load('models/bert-all-data.pth', map_location=device))
|
| 15 |
+
tokenizer = BertTokenizer.from_pretrained(model_name)
|
| 16 |
tokens = tokenizer(text, return_tensors='pt', max_length=512, padding='max_length', truncation=True).to(device)
|
| 17 |
prob = model(tokens['input_ids'], tokens['attention_mask']).item()
|
| 18 |
|