Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,33 +1,26 @@
|
|
| 1 |
from transformers import pipeline
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
-
classifier = pipeline(
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
"LABEL_1": "SPAM"
|
| 9 |
-
}
|
| 10 |
|
| 11 |
def predict_spam(text):
|
| 12 |
result = classifier(text)[0]
|
| 13 |
-
label =
|
| 14 |
confidence = round(result['score'] * 100, 2)
|
| 15 |
-
return f"
|
| 16 |
|
| 17 |
-
# Build Gradio UI
|
| 18 |
gr.Interface(
|
| 19 |
fn=predict_spam,
|
| 20 |
-
inputs=gr.Textbox(lines=4, placeholder="Enter
|
| 21 |
outputs="text",
|
| 22 |
-
title="
|
| 23 |
-
description="Detects SPAM
|
| 24 |
examples=[
|
| 25 |
-
"
|
| 26 |
-
"
|
| 27 |
-
"
|
| 28 |
-
"Click here to claim your reward."
|
| 29 |
]
|
| 30 |
).launch()
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
| 1 |
from transformers import pipeline
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
+
classifier = pipeline(
|
| 5 |
+
"text-classification",
|
| 6 |
+
model="mariagrandury/roberta-base-finetuned-sms-spam-detection"
|
| 7 |
+
)
|
|
|
|
|
|
|
| 8 |
|
| 9 |
def predict_spam(text):
|
| 10 |
result = classifier(text)[0]
|
| 11 |
+
label = "SPAM" if result['label'].lower() == "spam" else "HAM (Not Spam)"
|
| 12 |
confidence = round(result['score'] * 100, 2)
|
| 13 |
+
return f"Prediction: {label}\nConfidence: {confidence}%"
|
| 14 |
|
|
|
|
| 15 |
gr.Interface(
|
| 16 |
fn=predict_spam,
|
| 17 |
+
inputs=gr.Textbox(lines=4, placeholder="Enter your message..."),
|
| 18 |
outputs="text",
|
| 19 |
+
title="Spam Detector",
|
| 20 |
+
description="Detects whether a message is SPAM or not using a fine-tuned RoBERTa model.",
|
| 21 |
examples=[
|
| 22 |
+
"Congratulations! You won a prize.",
|
| 23 |
+
"Hi, are we meeting tomorrow?",
|
| 24 |
+
"Click to claim your free iPhone!"
|
|
|
|
| 25 |
]
|
| 26 |
).launch()
|
|
|
|
|
|
|
|
|