Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,6 @@ import gradio as gr
|
|
| 2 |
import torch
|
| 3 |
from transformers import pipeline
|
| 4 |
|
| 5 |
-
# 1. Load the phishing content detector pipeline
|
| 6 |
device = 0 if torch.cuda.is_available() else -1
|
| 7 |
detector = pipeline(
|
| 8 |
"text-classification",
|
|
@@ -11,23 +10,17 @@ detector = pipeline(
|
|
| 11 |
top_k=1,
|
| 12 |
)
|
| 13 |
|
| 14 |
-
# 2. Wrap prediction in a function for Gradio
|
| 15 |
def classify_text(text: str):
|
| 16 |
-
"""
|
| 17 |
-
Returns (label, score) for the given text.
|
| 18 |
-
Handles both flat and nested list outputs from the pipeline.
|
| 19 |
-
"""
|
| 20 |
if not text or not text.strip():
|
| 21 |
return "⚠️ Please enter some text", 0.0
|
| 22 |
|
| 23 |
preds = detector(text)
|
| 24 |
-
# If preds is [[{...}]], unwrap one level
|
| 25 |
first = preds[0][0] if isinstance(preds[0], list) else preds[0]
|
| 26 |
-
|
|
|
|
| 27 |
score = float(first["score"])
|
| 28 |
return label, round(score, 4)
|
| 29 |
|
| 30 |
-
# 3. Realistic example test cases
|
| 31 |
examples = [
|
| 32 |
# Phishing
|
| 33 |
["Congratulations! You've won a $1,000 gift card. Click here to claim: http://bit.ly/free-gift"],
|
|
@@ -48,7 +41,7 @@ with gr.Blocks(theme="default") as demo:
|
|
| 48 |
gr.Markdown(
|
| 49 |
"""
|
| 50 |
# 🚨 Phishing Content Detector
|
| 51 |
-
Paste any email or message snippet below and this model will predict whether it's **
|
| 52 |
"""
|
| 53 |
)
|
| 54 |
|
|
@@ -76,7 +69,7 @@ with gr.Blocks(theme="default") as demo:
|
|
| 76 |
|
| 77 |
gr.Markdown(
|
| 78 |
"""
|
| 79 |
-
**Model:** Version 1.
|
| 80 |
"""
|
| 81 |
)
|
| 82 |
|
|
|
|
| 2 |
import torch
|
| 3 |
from transformers import pipeline
|
| 4 |
|
|
|
|
| 5 |
device = 0 if torch.cuda.is_available() else -1
|
| 6 |
detector = pipeline(
|
| 7 |
"text-classification",
|
|
|
|
| 10 |
top_k=1,
|
| 11 |
)
|
| 12 |
|
|
|
|
| 13 |
def classify_text(text: str):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
if not text or not text.strip():
|
| 15 |
return "⚠️ Please enter some text", 0.0
|
| 16 |
|
| 17 |
preds = detector(text)
|
|
|
|
| 18 |
first = preds[0][0] if isinstance(preds[0], list) else preds[0]
|
| 19 |
+
raw = first["label"]
|
| 20 |
+
label = "Phishing" if raw == "LABEL_1" else "Legitimate"
|
| 21 |
score = float(first["score"])
|
| 22 |
return label, round(score, 4)
|
| 23 |
|
|
|
|
| 24 |
examples = [
|
| 25 |
# Phishing
|
| 26 |
["Congratulations! You've won a $1,000 gift card. Click here to claim: http://bit.ly/free-gift"],
|
|
|
|
| 41 |
gr.Markdown(
|
| 42 |
"""
|
| 43 |
# 🚨 Phishing Content Detector
|
| 44 |
+
Paste any email or message snippet below and this model will predict whether it's **Phishing** or **Legitimate**.
|
| 45 |
"""
|
| 46 |
)
|
| 47 |
|
|
|
|
| 69 |
|
| 70 |
gr.Markdown(
|
| 71 |
"""
|
| 72 |
+
**Model:** Version 1.0
|
| 73 |
"""
|
| 74 |
)
|
| 75 |
|