Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +22 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
# Load spam detection model pipeline
|
| 5 |
+
classifier = pipeline("text-classification", model="mrm8488/bert-tiny-finetuned-sms-spam-detection")
|
| 6 |
+
|
| 7 |
+
# Define the prediction function
|
| 8 |
+
def predict_spam(text):
|
| 9 |
+
result = classifier(text)[0]
|
| 10 |
+
label = result['label']
|
| 11 |
+
confidence = round(result['score'] * 100, 2)
|
| 12 |
+
return f"Prediction: {label}\nConfidence: {confidence}%"
|
| 13 |
+
|
| 14 |
+
# Gradio interface
|
| 15 |
+
gr.Interface(
|
| 16 |
+
fn=predict_spam,
|
| 17 |
+
inputs=gr.Textbox(lines=4, placeholder="Enter a message..."),
|
| 18 |
+
outputs="text",
|
| 19 |
+
title="Spam Detector",
|
| 20 |
+
description="Enter a message to check if it's spam or not using a pretrained BERT model.",
|
| 21 |
+
examples=["Win a free iPhone now!", "Hey, are we still on for dinner tonight?"]
|
| 22 |
+
).launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
transformers
|
| 2 |
+
gradio
|
| 3 |
+
torch
|