File size: 827 Bytes
35e1003
 
 
0784a7a
 
 
 
35e1003
 
 
0784a7a
35e1003
0784a7a
35e1003
 
 
0784a7a
35e1003
0784a7a
 
35e1003
0784a7a
 
 
35e1003
 
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
from transformers import pipeline
import gradio as gr

classifier = pipeline(
    "text-classification",
    model="mariagrandury/roberta-base-finetuned-sms-spam-detection"
)

def predict_spam(text):
    result = classifier(text)[0]
    label = "SPAM" if result['label'].lower() == "spam" else "HAM (Not Spam)"
    confidence = round(result['score'] * 100, 2)
    return f"Prediction: {label}\nConfidence: {confidence}%"

gr.Interface(
    fn=predict_spam,
    inputs=gr.Textbox(lines=4, placeholder="Enter your message..."),
    outputs="text",
    title="Spam Detector",
    description="Detects whether a message is SPAM or not using a fine-tuned RoBERTa model.",
    examples=[
        "Congratulations! You won a prize.",
        "Hi, are we meeting tomorrow?",
        "Click to claim your free iPhone!"
    ]
).launch()