TrioF commited on
Commit
86d5b3c
·
verified ·
1 Parent(s): db5031b

Initial upload

Browse files
Files changed (2) hide show
  1. app.py +28 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
3
+
4
+ # Load tokenizer and model from Hugging Face Hub
5
+ model_name = "TrioF/InSERT2"
6
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
7
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
8
+
9
+ # Create a pipeline
10
+ classifier = pipeline("text-classification", model=model, tokenizer=tokenizer)
11
+
12
+ # Inference function
13
+ def classify_text(text):
14
+ result = classifier(text)[0]
15
+ label = result["label"] # This will already be mapped using id2label from config.json
16
+ score = round(result["score"], 3)
17
+ return f"{label} ({score})"
18
+
19
+ # Build Gradio UI
20
+ demo = gr.Interface(
21
+ fn=classify_text,
22
+ inputs=gr.Textbox(lines=4, label="Masukkan pesan SMS/WA"),
23
+ outputs=gr.Textbox(label="Prediksi"),
24
+ title="Klasifikasi Pesan Spam Bahasa Indonesia",
25
+ description="Model ini mengklasifikasikan pesan menjadi 6 kategori: hadiah,lowongan/investasi, no spam, program pemerintah/bantuan, promo/penjualan, dan urgensi."
26
+ )
27
+
28
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ transformers
2
+ torch
3
+ gradio