Orawan commited on
Commit
e80fbcd
·
1 Parent(s): 1e2b810

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -19
app.py CHANGED
@@ -5,28 +5,24 @@ tokenizer = AutoTokenizer.from_pretrained("nlptown/bert-base-multilingual-uncase
5
  model = AutoModelForSequenceClassification.from_pretrained("nlptown/bert-base-multilingual-uncased-sentiment")
6
 
7
  # Create a sentiment analysis pipeline with the explicit tokenizer
8
- nlp = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
9
 
10
- st.title("Sentiment Analysis App")
11
- user_input = st.text_input("ป้อนประโยค:")
12
 
13
- # ตรวจจับข้อความเมื่อผู้ใช้คลิกปุ่ม "ตรวจสแปม"
14
- if st.button("ตรวจสแปม"):
 
 
 
15
  if user_input:
16
- # ใช้โมเดลในการตรวจจับสแปม
17
- result = nlp(user_input)
18
- label = result[0]['label']
19
- score = result[0]['score']
20
 
21
  # แสดงผลลัพธ์
22
- st.write(f"ผลการตรวจสแปม: {label}")
23
- st.write(f"คะแนนความเชื่อมั่น: {score:.4f}")
24
-
25
- # ตรวจสแปมและแสดงข้อความเตือน
26
- if label == "spam":
27
- st.warning("ข้อความนี้ถูกตรวจสแปม")
28
- else:
29
- st.success("ข้อความนี้ไม่ใช่สแปม")
30
  else:
31
- st.warning("โปรดป้อนข้อความเพื่อตรวจสแปม")
32
-
 
5
  model = AutoModelForSequenceClassification.from_pretrained("nlptown/bert-base-multilingual-uncased-sentiment")
6
 
7
  # Create a sentiment analysis pipeline with the explicit tokenizer
8
+ classifier = pipeline("text-classification", model=model)
9
 
10
+ # สร้างหน้าเว็บ Streamlit
11
+ st.title("Spam Detection App")
12
 
13
+ # สร้างกล่องข้อความให้ผู้ใช้ป้อนข้อความ
14
+ user_input = st.text_input("ใส่ข้อความที่ต้องการตรวจสอบ:")
15
+
16
+ # ตรวจสอบข้อความเมื่อผู้ใช้กดปุ่ม "ตรวจสอบ"
17
+ if st.button("ตรวจสอบ"):
18
  if user_input:
19
+ # ใช้โมเดลตรวจสอบข้อความ
20
+ result = classifier(user_input)
 
 
21
 
22
  # แสดงผลลัพธ์
23
+ st.write("ผลลัพธ์:")
24
+ st.write(f"ข้อความ: {user_input}")
25
+ st.write(f"สปัม: {result[0]['label']}")
26
+ st.write(f"ความมั่นใจ: {result[0]['score']}")
 
 
 
 
27
  else:
28
+ st.warning("โปรดป้อนข้อความก่อนตรวจสอบ")