File size: 2,400 Bytes
834791b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50c7b63
834791b
 
 
 
 
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import gradio as gr
import torch
from transformers import pipeline

device = 0 if torch.cuda.is_available() else -1
detector = pipeline(
    "text-classification",
    model="songhieng/roberta-phishing-content-detector-3.0",
    device=device,
    top_k=1,
)

def classify_text(text: str):
    if not text or not text.strip():
        return "⚠️ Please enter some text", 0.0

    preds = detector(text)
    first = preds[0][0] if isinstance(preds[0], list) else preds[0]
    raw = first["label"]
    label = "Phishing" if raw == "LABEL_1" else "Legitimate"
    score = float(first["score"])
    return label, round(score, 4)

examples = [
    # Phishing
    ["Congratulations! You've won a $1,000 gift card. Click here to claim: http://bit.ly/free-gift"],
    ["URGENT: Your PayPal account has been limited. Verify at https://secure-paypal-login.com"],
    ["Alert: Unrecognized login. Reset your password: http://tinyurl.com/reset-now"],
    ["Invoice overdue—pay now to avoid suspension: http://billing.example.com/pay"],
    ["Security Notice: Confirm your bank details here: https://bank-secure-update.com"],

    # Legitimate
    ["Your Amazon order has shipped! Track here: https://amazon.com/track"],
    ["Reminder: Zoom meeting with Marketing tomorrow at 3:00 PM."],
    ["Hey Jane, lunch at the café this Friday? 😊"],
    ["Your May utility bill is available. No action needed if on autopay."],
    ["Welcome to Acme’s Newsletter—our latest updates inside!"],
]

with gr.Blocks(theme="default") as demo:
    gr.Markdown(
        """
        # 🚨 Phishing Content Detector  
        Paste any email or message snippet below and this model will predict whether it's **Phishing** or **Legitimate**.
        """
    )

    inp = gr.Textbox(
        label="Input Text",
        placeholder="Paste email or message here…",
        lines=6,
    )
    label_out = gr.Textbox(label="Predicted Label")
    score_out = gr.Number(label="Confidence Score (0–1)")

    classify_btn = gr.Button("Classify")
    classify_btn.click(
        fn=classify_text,
        inputs=inp,
        outputs=[label_out, score_out],
    )

    gr.Examples(
        examples=examples,
        inputs=inp,
        cache_examples=False,
        label="Example Test Cases",
    )

    gr.Markdown(
        """
        **Model:** Version 3.0
        """
    )

if __name__ == "__main__":
    demo.launch()