parth parekh
commited on
Commit
·
6672218
1
Parent(s):
cd11250
added roberta again
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
from fastapi import FastAPI, HTTPException
|
2 |
from pydantic import BaseModel
|
3 |
import torch
|
4 |
-
from transformers import
|
5 |
from torch.nn.functional import softmax
|
6 |
import re
|
7 |
|
@@ -15,8 +15,8 @@ app = FastAPI(
|
|
15 |
class ContactDetector:
|
16 |
def __init__(self):
|
17 |
cache_dir = "/app/model_cache"
|
18 |
-
self.tokenizer =
|
19 |
-
self.model =
|
20 |
self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
21 |
self.model.to(self.device)
|
22 |
self.model.eval()
|
|
|
1 |
from fastapi import FastAPI, HTTPException
|
2 |
from pydantic import BaseModel
|
3 |
import torch
|
4 |
+
from transformers import RobertaTokenizer, RobertaForSequenceClassification
|
5 |
from torch.nn.functional import softmax
|
6 |
import re
|
7 |
|
|
|
15 |
class ContactDetector:
|
16 |
def __init__(self):
|
17 |
cache_dir = "/app/model_cache"
|
18 |
+
self.tokenizer = RobertaTokenizer.from_pretrained('roberta-base', cache_dir=cache_dir)
|
19 |
+
self.model = RobertaForSequenceClassification.from_pretrained('roberta-base', num_labels=2, cache_dir=cache_dir)
|
20 |
self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
21 |
self.model.to(self.device)
|
22 |
self.model.eval()
|