Spaces:
Sleeping
Sleeping
Download app.py from Orawan/Text_Classify: direct link, hf CLI and curl.
- Browser
- Download file 1.43 kB
-
https://huggingface.co/spaces/Orawan/Text_Classify/resolve/e80fbcd89a6b3db033b65b2887b3254ab187a5c2/app.py
- Command line
-
hf download hf://spaces/Orawan/Text_Classify@e80fbcd89a6b3db033b65b2887b3254ab187a5c2/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Orawan/Text_Classify/resolve/e80fbcd89a6b3db033b65b2887b3254ab187a5c2/app.py
1.43 kB
| 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 | |
| classifier = pipeline("text-classification", model=model) | |
| # สร้างหน้าเว็บ 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}") | |
| st.write(f"สปัม: {result[0]['label']}") | |
| st.write(f"ความมั่นใจ: {result[0]['score']}") | |
| else: | |
| st.warning("โปรดป้อนข้อความก่อนตรวจสอบ") |