Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,7 @@ from transformers import pipeline
|
|
| 2 |
import gradio as gr
|
| 3 |
import re
|
| 4 |
|
| 5 |
-
# Load models once
|
| 6 |
spam_pipe = pipeline("text-classification", model="Titeiiko/OTIS-Official-Spam-Model")
|
| 7 |
zero_shot = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
|
| 8 |
|
|
@@ -11,18 +11,19 @@ def is_gibberish(text: str) -> bool:
|
|
| 11 |
return len(text) == 0 or (letters / len(text) < 0.6)
|
| 12 |
|
| 13 |
def detect(text: str) -> dict:
|
| 14 |
-
# Ad/spam check
|
| 15 |
spam_flag = spam_pipe(text)[0]["label"] != "LABEL_0"
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
| 20 |
gibberish_flag = is_gibberish(text)
|
| 21 |
|
| 22 |
-
# Final decision
|
| 23 |
-
spam = spam_flag or
|
| 24 |
|
| 25 |
-
# Minimal output
|
| 26 |
return {
|
| 27 |
"input": text,
|
| 28 |
"spam": spam
|
|
@@ -33,7 +34,7 @@ demo = gr.Interface(
|
|
| 33 |
inputs=gr.Textbox(label="Enter complaint text"),
|
| 34 |
outputs=gr.JSON(label="Result"),
|
| 35 |
title="Spam Detector",
|
| 36 |
-
description="Returns only
|
| 37 |
)
|
| 38 |
|
| 39 |
if __name__ == "__main__":
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import re
|
| 4 |
|
| 5 |
+
# Load models once for speed
|
| 6 |
spam_pipe = pipeline("text-classification", model="Titeiiko/OTIS-Official-Spam-Model")
|
| 7 |
zero_shot = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
|
| 8 |
|
|
|
|
| 11 |
return len(text) == 0 or (letters / len(text) < 0.6)
|
| 12 |
|
| 13 |
def detect(text: str) -> dict:
|
| 14 |
+
# 1️⃣ Ad/spam check
|
| 15 |
spam_flag = spam_pipe(text)[0]["label"] != "LABEL_0"
|
| 16 |
+
|
| 17 |
+
# 2️⃣ Relevance check (anything not a complaint counts as spam)
|
| 18 |
+
zero_result = zero_shot(text, candidate_labels=["complaint", "not complaint"])
|
| 19 |
+
not_complaint_flag = zero_result["labels"][0] == "not complaint"
|
| 20 |
+
|
| 21 |
+
# 3️⃣ Gibberish check
|
| 22 |
gibberish_flag = is_gibberish(text)
|
| 23 |
|
| 24 |
+
# ✅ Final decision
|
| 25 |
+
spam = spam_flag or not_complaint_flag or gibberish_flag
|
| 26 |
|
|
|
|
| 27 |
return {
|
| 28 |
"input": text,
|
| 29 |
"spam": spam
|
|
|
|
| 34 |
inputs=gr.Textbox(label="Enter complaint text"),
|
| 35 |
outputs=gr.JSON(label="Result"),
|
| 36 |
title="Spam Detector",
|
| 37 |
+
description="Returns only the input and spam status (True/False)."
|
| 38 |
)
|
| 39 |
|
| 40 |
if __name__ == "__main__":
|