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