Spaces:
Running
Running
Update models.py
Browse files
models.py
CHANGED
@@ -1,20 +1,20 @@
|
|
1 |
-
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
2 |
-
import torch
|
3 |
-
|
4 |
-
def load_model():
|
5 |
-
model_path = "model"
|
6 |
-
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
7 |
-
model = AutoModelForSequenceClassification.from_pretrained(model_path)
|
8 |
-
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
9 |
-
model.to(device)
|
10 |
-
model.eval()
|
11 |
-
return tokenizer, model, device
|
12 |
-
|
13 |
-
def classify_email(text, tokenizer, model, device):
|
14 |
-
inputs = tokenizer(text, return_tensors="pt", max_length=256, padding="max_length", truncation=True)
|
15 |
-
inputs = {k: v.to(device) for k, v in inputs.items()}
|
16 |
-
with torch.no_grad():
|
17 |
-
logits = model(**inputs).logits
|
18 |
-
label_map = {0: "Incident", 1: "Request", 2: "Change", 3: "Problem"}
|
19 |
-
pred = torch.argmax(logits, dim=1).item()
|
20 |
-
return label_map[pred]
|
|
|
1 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
2 |
+
import torch
|
3 |
+
|
4 |
+
def load_model():
|
5 |
+
model_path = "sathish2352/email-classifier-model"
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
7 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_path)
|
8 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
9 |
+
model.to(device)
|
10 |
+
model.eval()
|
11 |
+
return tokenizer, model, device
|
12 |
+
|
13 |
+
def classify_email(text, tokenizer, model, device):
|
14 |
+
inputs = tokenizer(text, return_tensors="pt", max_length=256, padding="max_length", truncation=True)
|
15 |
+
inputs = {k: v.to(device) for k, v in inputs.items()}
|
16 |
+
with torch.no_grad():
|
17 |
+
logits = model(**inputs).logits
|
18 |
+
label_map = {0: "Incident", 1: "Request", 2: "Change", 3: "Problem"}
|
19 |
+
pred = torch.argmax(logits, dim=1).item()
|
20 |
+
return label_map[pred]
|