File size: 1,562 Bytes
8ccbec1
 
 
09c5b4d
 
8ccbec1
 
 
 
 
1e2b810
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline

tokenizer = AutoTokenizer.from_pretrained("nlptown/bert-base-multilingual-uncased-sentiment")
model = AutoModelForSequenceClassification.from_pretrained("nlptown/bert-base-multilingual-uncased-sentiment")

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

st.title("Sentiment Analysis App")
user_input = st.text_input("ป้อนประโยค:")

# ตรวจจับข้อความเมื่อผู้ใช้คลิกปุ่ม "ตรวจสแปม"
if st.button("ตรวจสแปม"):
    if user_input:
        # ใช้โมเดลในการตรวจจับสแปม
        result = nlp(user_input)
        label = result[0]['label']
        score = result[0]['score']

        # แสดงผลลัพธ์
        st.write(f"ผลการตรวจสแปม: {label}")
        st.write(f"คะแนนความเชื่อมั่น: {score:.4f}")

        # ตรวจสแปมและแสดงข้อความเตือน
        if label == "spam":
            st.warning("ข้อความนี้ถูกตรวจสแปม")
        else:
            st.success("ข้อความนี้ไม่ใช่สแปม")
    else:
        st.warning("โปรดป้อนข้อความเพื่อตรวจสแปม")