Create handler.py
Browse files- handler.py +15 -0
handler.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 2 |
+
import torch
|
| 3 |
+
|
| 4 |
+
class Handler:
|
| 5 |
+
def __init__(self):
|
| 6 |
+
self.model = AutoModelForSequenceClassification.from_pretrained(".")
|
| 7 |
+
self.tokenizer = AutoTokenizer.from_pretrained(".")
|
| 8 |
+
self.labels = ["presentation","projects","skills","education","contact","fallback"]
|
| 9 |
+
|
| 10 |
+
def inference(self, inputs):
|
| 11 |
+
encoded = self.tokenizer(inputs, return_tensors="pt")
|
| 12 |
+
with torch.no_grad():
|
| 13 |
+
logits = self.model(**encoded).logits
|
| 14 |
+
predicted_class = torch.argmax(logits, dim=1).item()
|
| 15 |
+
return {"label": self.labels[predicted_class], "score": 1.0} # score simplifié
|