File size: 2,375 Bytes
8ccbec1
 
 
ee6a206
 
8ccbec1
 
41c935a
8ccbec1
e80fbcd
 
1e2b810
e80fbcd
 
a34feba
e80fbcd
 
1e2b810
e80fbcd
 
1e2b810
 
e80fbcd
 
bc4bdd7
a34feba
 
55a51be
a34feba
55a51be
 
24fe33e
55a51be
 
 
a34feba
55a51be
a34feba
1e2b810
e80fbcd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import streamlit as st
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline

tokenizer = AutoTokenizer.from_pretrained("Nma/RuleClassify-Textclassify")
model = AutoModelForSequenceClassification.from_pretrained("Nma/RuleClassify-Textclassify")

# Create a sentiment analysis pipeline with the explicit tokenizer
classifier = pipeline("text-classification", model=model,tokenizer=tokenizer)

# สร้างหน้าเว็บ Streamlit
st.title("Spam Detection App")

# สร้างกล่องข้อความให้ผู้ใช้ป้อนข้อความ
user_input = st.text_input("ใส่ข้อความที่ต้องการตรวจสอบ:")

# ตรวจสอบข้อความเมื่อผู้ใช้กดปุ่ม "ตรวจสอบ"
if st.button("ตรวจสอบ"):
    if user_input:
        # ใช้โมเดลตรวจสอบข้อความ
        result = classifier(user_input)

        # แสดงผลลัพธ์
        st.write("ผลลัพธ์:")
        st.write(f"ข้อความ: {user_input}")
        
        # แสดงค่าความมั่นใจ
        confidence = result[0]['score'] * 100  # แปลงค่าความมั่นใจเป็นเปอร์เซ็นต์
        label = result[0]['label']

        if label == "LABEL_FOR_SPAM":  # แทน LABEL_FOR_SPAM ด้วยป้ายกำกับสแปมของโมเดลของคุณ
            st.write(f"สแปม: {label} ({confidence:.2f}% ความมั่นใจ)")
            if confidence >= 80:
                st.warning("โมเดลมั่นใจว่าข้อความนี้เป็นสแปม")
            else:
                st.success("โมเดลมั่นใจว่าข้อความนี้ไม่เป็นสแปม")
        else:
            st.write(f"ไม่เป็นสแปม: {label} ({confidence:.2f}% ความมั่นใจ)")
            st.success("โมเดลมั่นใจว่าข้อความนี้ไม่เป็นสแปม")
    else:
        st.warning("โปรดป้อนข้อความก่อนตรวจสอบ")