Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
# Load the model once (global)
|
| 5 |
+
pipe = pipeline("text-classification", model="Titeiiko/OTIS-Official-Spam-Model")
|
| 6 |
+
|
| 7 |
+
def is_spam(input_text: str) -> dict:
|
| 8 |
+
"""
|
| 9 |
+
Returns {"spam": bool, "label": str, "score": float}
|
| 10 |
+
"""
|
| 11 |
+
result = pipe(input_text)[0]
|
| 12 |
+
is_spam_flag = result["label"] != "LABEL_0"
|
| 13 |
+
return {
|
| 14 |
+
"spam": is_spam_flag,
|
| 15 |
+
"label": result["label"],
|
| 16 |
+
"score": float(result["score"])
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
# Gradio interface (for both API & UI)
|
| 20 |
+
demo = gr.Interface(
|
| 21 |
+
fn=is_spam,
|
| 22 |
+
inputs=gr.Textbox(label="Enter text"),
|
| 23 |
+
outputs=gr.JSON(label="Result"),
|
| 24 |
+
title="Spam Detector API",
|
| 25 |
+
description="Detect spam using Hugging Face Transformers."
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
if __name__ == "__main__":
|
| 29 |
+
demo.launch()
|