Update app.py
Browse files
app.py
CHANGED
|
@@ -8,20 +8,23 @@ detector = pipeline(
|
|
| 8 |
"text-classification",
|
| 9 |
model="songhieng/roberta-phishing-content-detector-1.0",
|
| 10 |
device=device,
|
| 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 |
"""
|
| 19 |
if not text or not text.strip():
|
| 20 |
return "⚠️ Please enter some text", 0.0
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
| 25 |
return label, round(score, 4)
|
| 26 |
|
| 27 |
# 3. Realistic example test cases
|
|
@@ -33,7 +36,7 @@ examples = [
|
|
| 33 |
["Invoice overdue—pay now to avoid suspension: http://billing.example.com/pay"],
|
| 34 |
["Security Notice: Confirm your bank details here: https://bank-secure-update.com"],
|
| 35 |
|
| 36 |
-
#
|
| 37 |
["Your Amazon order has shipped! Track here: https://amazon.com/track"],
|
| 38 |
["Reminder: Zoom meeting with Marketing tomorrow at 3:00 PM."],
|
| 39 |
["Hey Jane, lunch at the café this Friday? 😊"],
|
|
@@ -73,10 +76,9 @@ with gr.Blocks(theme="default") as demo:
|
|
| 73 |
|
| 74 |
gr.Markdown(
|
| 75 |
"""
|
| 76 |
-
**Model:** Version 1.
|
| 77 |
"""
|
| 78 |
)
|
| 79 |
|
| 80 |
if __name__ == "__main__":
|
| 81 |
-
# set share=True if you want a public link
|
| 82 |
demo.launch()
|
|
|
|
| 8 |
"text-classification",
|
| 9 |
model="songhieng/roberta-phishing-content-detector-1.0",
|
| 10 |
device=device,
|
| 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 |
+
label = first["label"]
|
| 27 |
+
score = float(first["score"])
|
| 28 |
return label, round(score, 4)
|
| 29 |
|
| 30 |
# 3. Realistic example test cases
|
|
|
|
| 36 |
["Invoice overdue—pay now to avoid suspension: http://billing.example.com/pay"],
|
| 37 |
["Security Notice: Confirm your bank details here: https://bank-secure-update.com"],
|
| 38 |
|
| 39 |
+
# Legitimate
|
| 40 |
["Your Amazon order has shipped! Track here: https://amazon.com/track"],
|
| 41 |
["Reminder: Zoom meeting with Marketing tomorrow at 3:00 PM."],
|
| 42 |
["Hey Jane, lunch at the café this Friday? 😊"],
|
|
|
|
| 76 |
|
| 77 |
gr.Markdown(
|
| 78 |
"""
|
| 79 |
+
**Model:** Version 1.
|
| 80 |
"""
|
| 81 |
)
|
| 82 |
|
| 83 |
if __name__ == "__main__":
|
|
|
|
| 84 |
demo.launch()
|