Spaces:
Sleeping
Sleeping
| 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("โปรดป้อนข้อความเพื่อตรวจสแปม") | |