Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
2 |
+
import torch
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
model_name = "Tlezz324/thai-scam-detector-v1.69"
|
6 |
+
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
8 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
9 |
+
|
10 |
+
def predict(text):
|
11 |
+
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
|
12 |
+
with torch.no_grad():
|
13 |
+
logits = model(**inputs).logits
|
14 |
+
pred = torch.argmax(logits, dim=1).item()
|
15 |
+
return "Scam" if pred == 1 else "Not Scam"
|
16 |
+
|
17 |
+
iface = gr.Interface(
|
18 |
+
fn=predict,
|
19 |
+
inputs=gr.Textbox(lines=4, placeholder="พิมพ์ข้อความที่ต้องการตรวจสอบ..."),
|
20 |
+
outputs="text",
|
21 |
+
title="Thai Scam Detector Demo",
|
22 |
+
description="โมเดลตรวจจับข้อความหลอกลวงภาษาไทย"
|
23 |
+
)
|
24 |
+
|
25 |
+
if __name__ == "__main__":
|
26 |
+
iface.launch()
|