|
|
import gradio as gr
|
|
|
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
|
|
|
|
|
|
|
|
|
model_name = "TrioF/InSERT2"
|
|
|
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
|
|
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
|
|
|
|
|
|
|
|
classifier = pipeline("text-classification", model=model, tokenizer=tokenizer)
|
|
|
|
|
|
|
|
|
def classify_text(text):
|
|
|
result = classifier(text)[0]
|
|
|
label = result["label"]
|
|
|
score = round(result["score"], 3)
|
|
|
return f"{label} ({score})"
|
|
|
|
|
|
|
|
|
demo = gr.Interface(
|
|
|
fn=classify_text,
|
|
|
inputs=gr.Textbox(lines=4, label="Masukkan pesan SMS/WA"),
|
|
|
outputs=gr.Textbox(label="Prediksi"),
|
|
|
title="Klasifikasi Pesan Spam Bahasa Indonesia",
|
|
|
description="Model ini mengklasifikasikan pesan menjadi 6 kategori: hadiah,lowongan/investasi, no spam, program pemerintah/bantuan, promo/penjualan, dan urgensi."
|
|
|
)
|
|
|
|
|
|
demo.launch() |