Spaces:
Sleeping
Sleeping
File size: 885 Bytes
35e1003 19d7e2f 53cb605 35e1003 53cb605 35e1003 53cb605 35e1003 53cb605 35e1003 53cb605 35e1003 53cb605 35e1003 53cb605 35e1003 9d659c3 53cb605 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
from transformers import pipeline
import gradio as gr
classifier = pipeline("text-classification", model="bhadresh-savani/bert-base-uncased-emotion")
label_map = {
"LABEL_0": "HAM (Not Spam)",
"LABEL_1": "SPAM"
}
def predict_spam(text):
result = classifier(text)[0]
label = label_map.get(result['label'], "Unknown")
confidence = round(result['score'] * 100, 2)
return f" Prediction: {label}\n Confidence: {confidence}%"
# Build Gradio UI
gr.Interface(
fn=predict_spam,
inputs=gr.Textbox(lines=4, placeholder="Enter a message..."),
outputs="text",
title=" Spam Detector",
description="Detects SPAM vs HAM using a pretrained BERT-tiny model.",
examples=[
"Win a free iPhone now!",
"Hey, are we still on for dinner tonight?",
"Your OTP is 456123.",
"Click here to claim your reward."
]
).launch()
|