File size: 369 Bytes
927b695
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
from transformers import pipeline

classifier = pipeline(
    "text-classification",
    model="mrm8488/bert-tiny-finetuned-sms-spam-detection"
)

def predict_text(text):
    result = classifier(text)[0]

    label = result["label"]
    score = result["score"]

    return {
        "prediction": label,
        "confidence": round(score * 100, 2)
    }