spam-detector / app.py
shrushhtijadhav's picture
Upload 2 files
3b45da0 verified
raw
history blame
802 Bytes
from transformers import pipeline
import gradio as gr
# Load spam detection model pipeline
classifier = pipeline("text-classification", model="mrm8488/bert-tiny-finetuned-sms-spam-detection")
# Define the prediction function
def predict_spam(text):
result = classifier(text)[0]
label = result['label']
confidence = round(result['score'] * 100, 2)
return f"Prediction: {label}\nConfidence: {confidence}%"
# Gradio interface
gr.Interface(
fn=predict_spam,
inputs=gr.Textbox(lines=4, placeholder="Enter a message..."),
outputs="text",
title="Spam Detector",
description="Enter a message to check if it's spam or not using a pretrained BERT model.",
examples=["Win a free iPhone now!", "Hey, are we still on for dinner tonight?"]
).launch()